Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lm #4

Merged
merged 3 commits into from
Oct 29, 2018
Merged

Lm #4

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public CharacterLanguageModel(){

// counts maps: history -> { word: count, word : count, etc }
counts = new HashMap<>();
order = 6;
order = 4;
}


Expand Down Expand Up @@ -173,6 +173,26 @@ public static List<String> string2list(String s){
return chars;
}

// this test is for a large file at :
// /shared/corpora/ner/clm/wikiEntity_train.out
public static void test2() throws Exception {
List<String> lines = LineIO.read("/shared/corpora/ner/clm/wikiEntity_train.out");
List<List<String>> seqs = new ArrayList<>();
for(String line : lines){
String[] chars = line.trim().split(" ");
ArrayList<String> seq = new ArrayList<String>(Arrays.asList(chars));
seqs.add(seq);
}

CharacterLanguageModel clm = new CharacterLanguageModel();
System.out.println(seqs.size());
clm.train(seqs);


System.out.println(clm.perplexity(Arrays.asList("H o e k s t e n b e r g e r".split(" "))));
System.out.println(clm.perplexity(Arrays.asList("a b s t r a c t u a l l y".split(" "))));
}

public static void test() throws FileNotFoundException {
String dir = "/home/mayhew/data/pytorch-example/data/names/";
File names = new File(dir);
Expand Down Expand Up @@ -243,21 +263,21 @@ public static void test() throws FileNotFoundException {

public static void main(String[] args) throws Exception {
// this trains models, and provides perplexities.
//test();
test2();

ParametersForLbjCode params = Parameters.readConfigAndLoadExternalData("config/ner.properties", false);
//ParametersForLbjCode params = Parameters.readConfigAndLoadExternalData("config/ner.properties", false);

// String trainpath= "/shared/corpora/ner/conll2003/eng-files/Train-json/";
// String testpath = "/shared/corpora/ner/conll2003/eng-files/Test-json/";

String trainpath= "/shared/corpora/ner/lorelei-swm-new/ben/Train/";
String testpath = "/shared/corpora/ner/lorelei-swm-new/ben/Test/";
//String trainpath= "/shared/corpora/ner/lorelei-swm-new/ara/Train/";
//String testpath = "/shared/corpora/ner/lorelei-swm-new/ara/Test/";


Data trainData = new Data(trainpath, trainpath, "-json", new String[] {}, new String[] {}, params);
Data testData = new Data(testpath, testpath, "-json", new String[] {}, new String[] {}, params);
//Data trainData = new Data(trainpath, trainpath, "-json", new String[] {}, new String[] {}, params);
//Data testData = new Data(testpath, testpath, "-json", new String[] {}, new String[] {}, params);

trainEntityNotEntity(trainData, testData);
//trainEntityNotEntity(trainData, testData);
}


Expand Down