Wednesday, 16 May 2012

Git - ssh authentication with key on windows.

Git - ssh authentication with key on windows.
As I've noticed there is a common problem setting up ssh connection with remote git repo without having to enter your password all the time. If you follow all "standard" procedures you'll be getting something like:
Access denied
fatal: The remote end hung up unexpectedly 
I don't know why this is happening, don't even want to know. So here is a quick recepie to avoid that.

1. set GIT_SSH environment variable to point to plink.exe [C:\putty\plink.exe]
2. ssh to remote host where repo is
3. cd ~
4. mkdir .ssh
5. cd .shh
6. ssh-keygen -t dsa (hit enter all the time)
7. cat id_dsa.pub >> authorized_keys
8. copy id_dsa to your windows machine (somewhere)
9. run puttygen.exe
10. press "Load" - open id_dsa file
11. press "Save private key" (save somewhere)
12. run pageant.exe
13. add key that you saved fro puttygen to pageant
14. git clone...
Should be working from now on, without need to provide password all the time.
Adapted from here

Tuesday, 1 May 2012

Sphinx4 custom acoustic model files notes.

The whole process of creating custom acoustic model is described here.
Read it thoroughly. If you are still not getting what are the required files and where to get them from this note is for you.

Given that structure is:

  1. etc
    1. your_db.dic - Phonetic dictionary
    2. your_db.phone - Phoneset file
    3. your_db.lm.DMP - Language model
    4. your_db.filler - List of fillers
    5. your_db_train.fileids - List of files for training
    6. your_db_train.transcription - Transcription for training
    7. your_db_test.fileids - List of files for testing
    8. your_db_test.transcription - Transcription for testing
  2. wav
    1. speaker_1
      1. file_1.wav - Recording of speech utterance
    2. speaker_2
      1. file_2.wav


Following files could be built by lmtool web service :
  1. your_db.dic - 
  2. Phonetic dictionary
  3. your_db.phone - Phoneset file
  4. your_db.filler - List of fillers
after you've got those files ready, you'll need .DMP file:
  1. your_db.lm.DMP - Language model
it is generated from .lm file with sphinx_lm_convert programm which is shipped with sphinxbase-7.0 archive. See this section on installation instructions of sphinxbase. You should use following commands to generate this file:

 sphinx_lm_convert -i model.lm -o model.dmp
sphinx_lm_convert -i model.dmp -ifmt dmp -o model.lm -ofmt arpa
After you've got that running, you should list all audio files that you want use for training and their matching phrases in remaining files:
  1. your_db_train.fileids - 
  2. List of files for training 
  3. your_db_train.transcription - Transcription for training

Ubuntu 11.10 install sphinxbase.

Ubuntu 11.10 install sphinxbase.

There is a good manual at http://cmusphinx.sourceforge.net/wiki/tutorialpocketsphinx
Anyways. After you've downloaded and unpacked sphinx-0.7 archive

1. ./autogen.sh (It won't start right away, but will print what software packages are missing)
2. sudo apt-get install autoconf
3. sudo apt-get install libtool
4. sudo apt-get install automake
5. sudo apt-get install bison
6. sudo ./autogen.sh
8. sudo make
9. sudo make install 
10. export LD_LIBRARY_PATH=/usr/local/lib
Now try
sphinx_lm_convert
If you can see following message:
 ERROR: "cmd_ln.c", line 675: No arguments given, available options are:
Arguments list definition:
[NAME] [DEFLT] [DESCR]
-case Ether 'lower' or 'upper' - case fold to lower/upper case (NOT UNICODE AWARE)
-debug Verbosity level for debugging messages
-help no Shows the usage of the tool
-i Input language model file (required)
-ienc Input language model text encoding (no conversion done if not specified)
-ifmt Input language model format (will guess if not specified)
-logbase 1.0001 Base in which all log-likelihoods calculated
-mmap no Use memory-mapped I/O for reading binary LM files
-o Output language model file (required)
-oenc utf8 Output language model text encoding
-ofmt Output language model file (will guess if not specified)
Than everything works fine.
NOTE: this is required step to start training your own acoustic models for CMU Sphinx 4. 

Thursday, 26 April 2012

Spring-MongoDB: Checking if data member is of array type in map function.

If you'll ever have to do things like that, following code worked out perfectly for me:
if( Object.prototype.toString.call( myObj ) === '[object Array]' ) {}
source: http://stackoverflow.com/questions/4775722/javascript-check-if-object-is-array 

Spring-MongoDB: debugging map\reduce on ubuntu.

while using Spring-data-MongoDB on ubuntu system, with default mongo installation you migh be experiencing troubles with error messages, as they might look similar to this:
InvalidDataAccessApiUsageException: Command execution failed:  Error [db assertion failure], Command = { "mapreduce" : ... }
The error message will include whole command, an will give you no clues about what actually went wrong. Try executing following command from terminal and repeat issue:
 tail -f /var/log/mongodb/mongodb.log 
trace information will get printed to log and you'll see it in terminal.  You should be looking for messages as following:

 JS Error: TypeError: myVar has no properties nofile_b:69
You can also add print to log in map\reduce functions with print("...") method invocation.
print('variable state is : ' + myVar) ;

 

Tuesday, 24 April 2012

Spring-Data-MongoDB passing scope variables to map\reduce

Spring-Data-MongoDB passing scope variables to map\reduce:

It's becoming a little bit tricky if you want to pass something like wrapper that contains Map of Map's as a parameter to map\reduce.

Anyhow, If you'll find yourself in trouble passing parameters to map\reduce here is one way to handle it:


MapReduceOptions options = MapReduceOptions.options();
Map vars = new HashMap();
        try {
            ObjectMapper mapper = new ObjectMapper();
            DBObject dbo = new BasicDBObject(mapper.convertValue(myobject, Map.class));
            vars.put("myparamName",dbo);
        } catch (Exception e) {
            logger.error(e);
        }
        options.scopeVariables(vars);
this way scope parameter will be passed as a pure JSON map object, which will be automatically mapped to js object by MongoDB.

ObjectMapper is a Jackson framework class.

Saturday, 21 April 2012

JSON serialization of JS objects with Spring.

JSON serialization of JS objects with Spring.

Problem: pass JS object from spring MVC enabled backend to HTML page, use eval (...) on object and invoke function that have been passed from backend.

Solution: By default Spring framework is using Jackson to serialize Java objects. During that serialization all members are passed as strings, while we'd like to have data structure as following:

{
    member1 : "value1",
    action : function() {
             ...
    }
}
with such an object it would be possible to do the following to invoke function:
 obj.action()
 In order to do that one would have to implement custom serializer class

public class MySerializer extends JsonSerializer<MyTO> {
    public void serialize(MyTO value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException {
        jgen.writeStartObject();
        jgen.writeObjectField("member1", value.getMember1());
        jgen.writeFieldName("action");
        jgen.writeRaw(":" + value.getAction());
    }
}

Done. use eval on front end to convert JSON into actual JS object and enjoy.