Google+

Saturday, November 16, 2019

Create pkg MacOS installer with macos-installer-builder

We are going to create a pkg that copies some files to the /Library directory. We will use the tool macos-installer-builder, which could be downloaded from https://github.com/KosalaHerath/macos-installer-builder

The usage of this tool has been well explained in the github page. The default build-macos-x64.sh script requires two parameters: product name and product version. We are going to modify this script to generate a pkg installer that copies the application files into a fixed directory.

1. copy the application's files into ./application/ folder
2. comment the section in #Argument validation which validates the product name and product version parameters. Since we are not going to use the input parameters.
3. change PRODUCT and VERSION variables to strings.
4. change in function copyBuildDirectory the three commands below #Copy cellery product to /Library/Cellery, \${PRODUCT}/\${VERSION} to the fixed target directory
5. comment createUninstaller command, since I don't use it.
6. add commands in postinstall script, such as changing the permission.

Finally, run bash build-macos-x64.sh to generate the pkg installer.


Monday, October 28, 2019

Compile and load kext

The problem is that I use MacOS 10.15, and the sdk is already installed in the folder:

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/

So if I do "ls" to this folder, it shows:

DriverKit19.0.sdk MacOSX.sdk MacOSX10.15.sdk

Now I need to copy 10.14 sdk to this folder. The first thing I did is "svn export" the 10.14 sdk from

https://github.com/alexey-lysiuk/macos-sdk/tree/master/MacOSX10.14.sdk

I use this command, replace "tree/master" by "trunk":

svn export https://github.com/alexey-lysiuk/macos-sdk/trunk/MacOSX10.14.sdk

Then I "sudo cp -r" this folder to my SDKs folder. For compiling the project, I used:

xcodebuild -project "projectName.xcodeproj" -scheme "schemeName" -sdk macosx10.14 -derivedDataPath build clean build

Finally I changed the ownership of the kext:

sudo chown -R root:wheel yourKext.kext


Wednesday, August 28, 2019

My understanding of Word Insertion Penalty

In Daniel Jurafsky and James H. Martin's book Speech and Language Processing 2nd edition, page 317, the concept of Word Insertion Penalty has been introduced. But it's very confusing to me. The original description is

(on average) the language model probability decreases (causing a larger penalty), the decoder will prefer fewer, longer words. If the language model probability increases (larger penalty), the decoder will prefer more shorter words. 

Pay attention that larger penaly appeared twice in two opposite conditions: when language model probability decreases and increases. This is not logical and I guess it's a typo of this book.

My understanding is:

If the language model probability doesn't take enough weight (importance), the decoder will prefer more shorter words since the multiplier of the language probabilities of all of the words would be small compared to acoustic probabilities. The language model scaling factor does reduce the weight of language model so that the Word Insertion Penalty should be introduced to avoid many insertions.

Tuesday, February 20, 2018

Retrieve the final hidden states output of variable length sequences in Tensorflow

Assume you have an input batch which contains variable length sequences. The batch dimension is:

input: [batch_size, max_time, dim_feature]

and you also stored the length of each sequence in a vector, say sequence_length. Now you can easily get the states output by:

_, state = tf.nn.dynamic_rnn(some_RNN_cell, input, sequence_length=sequence_length)

then you can get both the hidden and cell states output:

state.h: hidden states output, [batch_size, hidden_states_size]
state.c: cell states output

I give credit to these two sources:
https://danijar.com/variable-sequence-lengths-in-tensorflow/
https://github.com/shane-settle/neural-acoustic-word-embeddings/blob/4cc3878e6715860bcce202aea7c5a6b7284292a1/code/lstm.py#L25


Sunday, January 14, 2018

Sheet music and audio multimodal learning

https://arxiv.org/abs/1612.05050

Toward score following in sheet music: use classification to find note head position in the sheet music. Given an audio spectrogram patch, classify the location bucket.

https://arxiv.org/abs/1707.09887

Learning audio - sheet music correspondences for score identification and offline alignment: pair wise ranking objective and contrastive loss (siamese), what's the difference?

Wednesday, January 3, 2018

If I were to write this paper... Drum transcription CRNN

https://ismir2017.smcnus.org/wp-content/uploads/2017/10/123_Paper.pdf

(1) I will specify the dropout size used for the BGRU layers, unless we can attribute the better performance of the CBGRU to overfitting.

(2) I will report the parameter numbers of different models. For sure, a model with more parameters will have more capacity. In such way, the better performance of CBGRU-b than the CNN-b could be attributed its larger parameter size.

(3) The CNN-b seems to perform really well. I will fix the Conv layers in CNN-b model, switch the Dense layers to GRU layers to see if GRU can really outperform.

Wednesday, December 27, 2017

Capacity and trainability of different RNNs

In the paper "Capacity and trainability in RNNs": https://arxiv.org/pdf/1611.09913.pdf

The author claims that all common RNNs have similar capacity. The Vanilla RNN is super hard to train. If the task is hard to learn, one should choose gated architectures, in which GRU is the most learnable for shallow networks, +RNN (Intersection RNN) performs the best for the deep networks. Although LSTM is extremely reliable, it doesn't perform the best. If the training environment is uncertain, the author suggests using GRU or +RNN.

Another paper "On the state of the art of evaluation in neural language models" https://arxiv.org/pdf/1707.05589.pdf The authors also found that the standard LSTM performs the best among 3 different architectures (LSTM, Recurrent highway networks and Neural architecture search). The models are trained using a modified ADAM optimizer. Hyperparameters including learning rate, input embedding ratio, input dropout, output dropout, weight decay, are tuned by batched GP bandits.

It is also shown that, in the Penn Treebank experiment, for the recurrent state, the variational dropout helps, the recurrent dropout indicates no advantage.

Sunday, December 24, 2017

Deep learning practice and trends, some key points

I went through the 1st part of the tutorial: practice. Below are some key points in Oriol's talk:

CNN:

(1) The slide 7 Deep learning: zooming in is amazing! He listed the deep learning model construction elements and sorted them into different categories: Non-linearities, Optimizer, connectivity pattern, loss and hyper-parameters.

(2) The slide 21 which shows the convolution animation is great! very intuitive to understand the convolution mechanism.

(3) Slide 27 building very deep ConvNets: using deeper architecture and small filter size 3*3 will result in a large receptive field and less parameter size than using large filters.

(4) Slide 35 U-net: for image segmentation, bottleneck encoder-decoder with skip connection.

Seq2seq:

(1) Attention!

(2) Slide 62: tricks!

Video:

Slides: https://docs.google.com/presentation/d/e/2PACX-1vQMZsWfjjLLz_wi8iaMxHKawuTkdqeA3Gw00wy5dBHLhAkuLEvhB7k-4LcO5RQEVFzZXfS6ByABaRr4/pub?slide=id.g2a19ddb012_0_654

Monday, November 27, 2017

Formant and resonance in western and Kunqu opera singing, litterature

http://somaticvoicework.com/resonance-strategies-and-formant-tuning/
blog讲了美声应该调整比如第一formant适应基频,第二formant来适应第二谐波。塑造音色的靠前5个formants。但是跟学生讲这些jargon是没有用的,因为学生不知道怎么做。调整声音的变量特别多,比如:

The formants align because of the pitch, the volume and the vowel sound, and the shape we make while singing one. There are multitudes of possibilities with vowel sound shapes and very small differences can make the sound “maximally efficient” or not quite “good enough”. The jaw, the tongue, the mouth/lips, the back of the mouth (velo-pharyngeal port), the height of the back of the tongue, the height of the larynx and the amount of open/closed quotient as well as the depth of the vocal folds during vibration all play a part in the overall sound we hear when someone sings. The “at rest” position of the length of the folds, the size of the larynx, the size (both diameter and length of the vocal tract) of the throat and mouth cavities, and the bones of the head and face all play a part as well. And “resonance” as a destination isn’t needed in anything but classical repertoire and some kinds of music that might be done acoustically.

blog指出找到好音色的方法还是学生跟着老师不断练习。老师要通过学生演唱的听觉和视觉信息来纠正。就好比老师是一个函数,输入是学生的演唱音频和视频,输出是如何纠正与提高的方法。

https://www.ncbi.nlm.nih.gov/pubmed/23453594
Sundberg讨论第一共振峰的位置和基音的关系。他测量了美声和非美声歌手唱几个不同的vowel,不同的频率,并没有发现共振峰跟随基音有系统性的改变。同时,高阶的共振峰也没有发现跟随基音有系统改变。

https://www.ncbi.nlm.nih.gov/pubmed/24902631
CONCLUSIONS: Formant tuning may be applied by a singer of the OM (old man) role, and both CF (color face) and OM role singers may use a rather pressed type of phonation, CF singers more than OM singers in the lower part of the pitch range. Most singers increased glottal adduction with rising F0.

https://www.ncbi.nlm.nih.gov/pubmed/24131362
测量了10个昆曲演员的long-term-average-spectrum,5个行当。没有发现singing formant, 发现花脸在3kHz位置有speaker formant. LTAS跟普通说话人的差别很大,跟美声的差别也很大。

Saturday, November 25, 2017

Optimizing DTW-based audio-to-MIDI alignment and matching, Colin Raffel paper

This paper introduced a method of optimizing various DTW parameters on a synthetic MIDI dataset. He optimized the mean absolute alignment error by Bayesian optimization and the confidence score by exhaustive search.

Some interesting points in the paper:
(1) The best alignment systems don't use beat-synchronous feature.

(2) He introduced two penalties. The first one to penalize the "non-diagonal move", the second to ensure the entire subsequence is used when doing subsequence alignment. Best systems use median values for both penalties.

(3) The synthetic midi method includes change tempo, crop midi segment, delete the vocal track, change instrument timbre and change velocity. All is done by pretty_midi.

(4) He evaluated the matching confidence score by calculating the Kendell rank correlation between the score and the alignment absolute error, which means the error is the ground truth matching confidence score.

(5) All of the systems achieved the highest correlation when including the penalties in the score calculation, normalizing by the path length, and normalizing by the mean distance across the aligned portions.

Friday, November 24, 2017

Deep learning, where are you going?

A talk by Kyunghyun Cho, a professor from New York univ. The name is "Deep learning, where are you going?" Things to take away for me:

(1) Currently, most people using neural network to do one specific task. They grab the data and annotation, build an architecture and train the model. However,  as time goes, the trained model become isolated because new information comes around. In such way, we have to retrain the model with newly collected data. So how could we benefit with the pre-trained model? The idea would be combining different pre-trained models to do a more complex task or using another neural net to interpret the pre-trained model.

(2) The idea of multilingual translation is to train a shared continuous language space (word, character). He found char2char model is better than word2word or word2char models. Additionally, you can do mixed languages translation where the input sentence is mixed with such as English, French, etc.

Friday, July 10, 2015

Git most often used command

1. add untracked files: git add *
2. show status in a git folder: git status
3. remove file A in git folder: git rm A
4. rename A to B: git mv A B
5. commit with comment: git commit -m 'message'
6. push: git push

Monday, July 6, 2015

git ssh low speed push solution

git push uses ssh, if you meet low speed push problem, try do this:
  1. $ git remote -v
  2. if you see your git folder begins with http://, please use
    git remote set-url origin commande to change it to ssh url.
  3. $ sudo sysctl -w net.ipv4.tcp_sack=0
  4. then git push

Friday, May 22, 2015

Set JRE environment for smartgit in Linux

1. download smartgit linux version, try run ./smartgit.sh in the its bin folder
2. if it complains JRE version problem, run sudo apt-get install openjdk-7-jre
3. locate to your openjdk-7-jre path, see here 
4. gedit ~/.smartgit/smartgit.vmoptions, add line: jre = path-to-your-openjdk
5. redo step 1

Saturday, April 18, 2015

Youtube data client library iOS, oauth2, HTTPfetcher

1. Compiling google api

This page shows the method to compile the google api to a project. I used the second way: compiling the source files directly into iOS project.

When I downloaded its source file, the oauth2 and HTTPfetcher are not there. We need to download them separately from here and here. Then just follow the procedure in the first page to finish compiling.

2. Youtube search

To search the data on youtube, firstly, import three headers:

#import "GTLServiceYouTube.h"
#import "GTLQueryYouTube.h"
#import "GTLYouTubeSearchListResponse.h"

Then for example, we search here for the youtube id by giving a searching word string:

GTLServiceYouTube *service = [[GTLServiceYouTube alloc] init];
service.APIKey = yourAPIKey;
GTLQueryYouTube *query = [GTLQueryYouTube queryForSearchListWithPart:@"id"];
query.type = @"video";
query.q = aSearchingString;
query.maxResults = aInt;

The code is very clear itself. We declare a youtube service instance, give it the APIKey, declare a query instance. The meaning of type, q and maxResults can be found here. Finally we execute this query which will give us a ticket. In the completionHandler, we receive the returned object.

GTLServiceTicket *ticketSend = [service executeQuery:query
                                   completionHandler:^(GTLServiceTicket *ticketReceive, id object, NSError *error)
    {
        if (!error) {
            GTLYouTubeSearchListResponse *items = object;
            }
        } else {
           
        }
    }];

Wednesday, March 18, 2015

Install Scipy through pip install in mac os x

When canopy visual environment has been installed, you might find your can't install Scipy to /usr/local/lib/python2.7/ anymore, or you might encounter pip "DistributionNotFound" Error. The solution is to reinstall python like this, using the soft way. Then pip install scipy.

Python package "intonation" needs Scipy.

Plot histogram of a recording object might cause float error in mac os backend.  Try to use:

import matplotlib
matplotlib.use("Qt4Agg")

before import anything from pylab.

Tuesday, March 3, 2015

Using AcoustID in IOS

AcoustID is an audio finger print project where Chromaprint allows you to calculate finger print from audio sources, and its web service allows you to search or to submit audio information in its database by Chromaprint.

Chormaprint is the core component of AcoustID project, it is written in C and can be compiled by cmake. However to use it in IOS, one needs a toolchain file.

1. Compile Chromaprint for IOS
1) You need to download the toolchain file here: https://code.google.com/p/ios-cmake/source/browse/

2) unzip the file "iOS.cmake" to Chromaprint source files' root folder. Open it, then change IOS_PLATFORM according to what you need. The default building architecture for "OS" is armv7 and arm64, this is sufficient for nowadays IOS devises.

3) build source files into a static library

1. mkdir build.ios 
2. cd build.ios 
3. cmake -DCMAKE_TOOLCHAIN_FILE=../../../iOS.cmake -GXcode ..
4. open Xcode project, compile chromaprint_p target for "iOS Device"

4) the static library will appear in the folder src/Debug-iphoneos/libchromaprint_p.a

2. Calculate finger print
Chromaprint only receives LinearPCM as the input audio format, so one should do the conversion if his original audio file format is not LinearPCM. The conversion method can be consulted here.

Once we get the URL of the audio file, we can open it by function AudioFileOpenURL, and save the fileID to outAudioFile.

The procedure of the finger print calculation is:

1. define a finger print calculation algorithm, here we use the default one: 
int algo = CHROMAPRINT_ALGORITHM_DEFAULT.

2. declare a finger print context and start calculation:
ChromaprintContext chromaprintCtx = chromaprint_new(algo);
chromaprint_start(chromaprintCtx, samplerate, channels);

3. read data packet, feed audio buffer outBuffer into this context, this could be done in a while loop:
AudioFileReadPackets(outAudioFile, false, &outNumBytes, NULL, inStartingPacket,&ioNumPackets, outBuffer);
chromaprint_feed(chromaprintCtx, outBuffer, ioNumPackets * framesPerPackets * 2)
where ioNumPackets is the packet number of the buffer,  inStartingPacket is the starting packet of the buffer, framesPerPackets = 1 for linearPCM audio format. Notice that AcoustID web service needs only 2 minutes audio finger print for database searching.

4. finish the finger print calculation and finally get the finger print:
chromaprint_finish(chromaprintCtx)
char *fingerPrint;
chromaprint_get_fingerprint(chromaprintCtx, &fingerPrint)

Now we have the finger print, and we can use it with AcoustID API to search its database.

Friday, January 23, 2015

AB Jukebox FAQ English

1. A simple tutorial

1) Download music information at first launch


2) Manually start/stop download in Settings.



3) You can download single's song's information in Library.


4) Enable/disable Download when launching in Settings.


5) Choose horizontal/vertical features (mood, timbre, rhythm)


6) 10 features available

7) Choose songs by drawing


 8) Play!


9) You can watch this simple tutorial in app Settings.


2. Browse song information in Wikipédia

1) Tap a song point on feature pad, then tap its title.


2) Swipe left a song cell in Playlist.


3) Swipe left a song cell in Library.


4) You can search Wikipédia by song title, artist name or album name.



3. What's the two points on the right of a song in Library?


The upper point is an indicator of MusicBrainz (www.musicbrainz.org), the lower point is an indicator of AcousticBrainz (acousticbrainz.org). 

The blue color means this song's information has been found in the database. The gray color means its information has not been found in the database.

4. Why I can't find some songs (or all of them) on the feature pad?


1) One possible reason is your unfound music files are not tagged properly. AcousticBrainz Jukebox queries song information from database by matching its song title, artist name and album title (optional).

You can download music tagging software Picard, and tag your unfound music files. A tutorial of tagging music file can be found here.

2) If you still can't find these songs on pad, it's probably that the information of these music don't exist in database. You can use this software to calculate the information and then upload it to the database.

Tuesday, January 13, 2015

Hide UITableView index of empty sections iOS

In iOS, we use "UILocalizedIndexedCollation" to partition music library song objects into sections to display them in table view. The "sectionTitles" array of "currentCollation" instance contains all letters in alphabet from A to Z if our system preferred language is English.

UILocalizedIndexedCollation *collation = [UILocalizedIndexedCollation currentCollation];
NSArray *sectionTitles = [collation sectionTitles];

Sometimes, due to lack of song titles which begin with certain letters, we have empty sections. For the sake of redundancy, we don't want display their titles and indexes in table view.

To hide them, we could declare a NSMutableArray to store those sections which are not empty:

// declare this in @interface
@property (nonatomic, strong) NSMutableArray *sectionIndexTitles;

// put this snippet in objects partition function
int i = 0;
for (NSMutableArray *section in unsortedSections) {
    if ([section count] != 0) {
        [sections addObject:[collation sortedArrayFromArray:section collationStringSelector:selector]];
        [self.sectionIndexTitles addObject:[[collation sectionIndexTitles] objectAtIndex:i]];
    }
    i++;
}

Finally we set up the table view delegate methods by using our "sectionIndexTitles":

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return [self.sectionIndexTitles count];
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
    return [self.sectionIndexTitles objectAtIndex:section];
}

- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView {
    return self.sectionIndexTitles;
}

// touching the index jump to corresponding section
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index {
    return [self.sectionIndexTitles indexOfObject:title];

Read this article to know how to configure UITableView by UILocalizedIndexedCollation.