Skip to content

WordEmbedding Tests added plus added dimension check for the first row #880

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

Merged
merged 3 commits into from
Sep 12, 2018
Merged
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
15 changes: 8 additions & 7 deletions src/Microsoft.ML.Transforms/Text/WordEmbeddingsTransform.cs
Original file line number Diff line number Diff line change
@@ -426,13 +426,14 @@ private Model GetVocabularyDictionary()
dimension = wordsInFirstLine.Length - 1;
if (model == null)
model = new Model(dimension);
float temp;
string firstKey = wordsInFirstLine[0];
float[] firstValue = wordsInFirstLine.Skip(1).Select(x => float.TryParse(x, out temp) ? temp : Single.NaN).ToArray();
if (!firstValue.Contains(Single.NaN))
model.AddWordVector(ch, firstKey, firstValue);
else
ch.Warning($"Parsing error while reading model file: '{_modelFileNameWithPath}', line number 1");
if (model.Dimension == dimension)
{
float temp;
string firstKey = wordsInFirstLine[0];
float[] firstValue = wordsInFirstLine.Skip(1).Select(x => float.TryParse(x, out temp) ? temp : Single.NaN).ToArray();
if (!firstValue.Contains(Single.NaN))
model.AddWordVector(ch, firstKey, firstValue);
}
pch.Checkpoint(lineNumber);
}
}
Original file line number Diff line number Diff line change
@@ -20,14 +20,16 @@ internal class EmptyWriter : TextWriter
public override Encoding Encoding => null;
}

public class BigramAndTrigramBenchmark
public class MultiClassClassification
{
private string _dataPath_Wiki;
private string _modelPath_Wiki;

[GlobalSetup(Targets = new string[] {
nameof(CV_Multiclass_WikiDetox_BigramsAndTrichar_OVAAveragedPerceptron),
nameof(CV_Multiclass_WikiDetox_BigramsAndTrichar_LightGBMMulticlass) })]
nameof(CV_Multiclass_WikiDetox_BigramsAndTrichar_LightGBMMulticlass),
nameof(CV_Multiclass_WikiDetox_WordEmbeddings_OVAAveragedPerceptron),
nameof(CV_Multiclass_WikiDetox_WordEmbeddings_SDCAMC)})]
public void SetupTrainingSpeedTests()
{
_dataPath_Wiki = Path.GetFullPath(TestDatasets.WikiDetox.trainFilename);
@@ -81,5 +83,25 @@ public void Test_Multiclass_WikiDetox_BigramsAndTrichar_OVAAveragedPerceptron()
Maml.MainCore(tlc, cmd, alwaysPrintStacktrace: false);
}
}

[Benchmark]
public void CV_Multiclass_WikiDetox_WordEmbeddings_OVAAveragedPerceptron()
{
string cmd = @"CV tr=OVA{p=AveragedPerceptron{iter=10}} k=5 loader=TextLoader{quote=- sparse=- col=Label:R4:0 col=rev_id:TX:1 col=comment:TX:2 col=logged_in:BL:4 col=ns:TX:5 col=sample:TX:6 col=split:TX:7 col=year:R4:3 header=+} data=" + _dataPath_Wiki + " xf=Convert{col=logged_in type=R4} xf=CategoricalTransform{col=ns} xf=TextTransform{col=FeaturesText:comment tokens=+ wordExtractor=NGramExtractorTransform{ngram=2}} xf=WordEmbeddingsTransform{col=FeaturesWordEmbedding:FeaturesText_TransformedText model=FastTextWikipedia300D} xf=Concat{col=Features:FeaturesText,FeaturesWordEmbedding,logged_in,ns}";
using (var tlc = new TlcEnvironment(verbose: false, sensitivity: MessageSensitivity.None, outWriter: EmptyWriter.Instance))
{
Maml.MainCore(tlc, cmd, alwaysPrintStacktrace: false);
}
}

[Benchmark]
public void CV_Multiclass_WikiDetox_WordEmbeddings_SDCAMC()
{
string cmd = @"CV tr=SDCAMC k=5 loader=TextLoader{quote=- sparse=- col=Label:R4:0 col=rev_id:TX:1 col=comment:TX:2 col=logged_in:BL:4 col=ns:TX:5 col=sample:TX:6 col=split:TX:7 col=year:R4:3 header=+} data=" + _dataPath_Wiki + " xf=Convert{col=logged_in type=R4} xf=CategoricalTransform{col=ns} xf=TextTransform{col=FeaturesText:comment tokens=+ wordExtractor={} charExtractor={}} xf=WordEmbeddingsTransform{col=FeaturesWordEmbedding:FeaturesText_TransformedText model=FastTextWikipedia300D} xf=Concat{col=Features:FeaturesWordEmbedding,logged_in,ns}";
using (var tlc = new TlcEnvironment(verbose: false, sensitivity: MessageSensitivity.None, outWriter: EmptyWriter.Instance))
Copy link
Member

@sfilipi sfilipi Sep 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indent those, maybe, for readability

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indent the cmd or tlc environment ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cmd


In reply to: 217119176 [](ancestors = 217119176)

{
Maml.MainCore(tlc, cmd, alwaysPrintStacktrace: false);
}
}
}
}