docs icon indicating copy to clipboard operation
docs copied to clipboard

Microsoft.ML sentiment-analysis results issue with different versions of Microsoft.ML

Open mathewknott opened this issue 8 years ago • 25 comments

Seems to be an issue with this sample

The sample works with Nuget Package Microsoft.ML 0.3.0 When running 0.4.0 you get different results.

That is, both results in the console are positive for 0.4.0. The first result should be negative if it is supposed to be the same as 0.3.0, which I'd assume it would.


Document details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

mathewknott avatar Aug 15 '18 14:08 mathewknott

Same issue, get both as positive even if I use exact wording from sample, i.e. 'RUDE' Also noted that if use 2.0 in csproj file get lowere percentages than if use 2.1. Tried bringing in the csproj, project.cs and SentimentData.cs files from samples on GitHub but got the same, thats how I saw the test results differ based on .net core version

LogOg avatar Aug 15 '18 16:08 LogOg

Indeed, output with 0.3.0 version:

PredictionModel quality metrics evaluation
------------------------------------------
Accuracy: 66.67%
Auc: 94.44%
F1Score: 75.00%

Sentiment Predictions
---------------------
Sentiment: Please refrain from adding nonsense to Wikipedia. | Prediction: Negative
Sentiment: He is the best, and the article should say that. | Prediction: Positive

Output with 0.4.0 version:

PredictionModel quality metrics evaluation
------------------------------------------
Accuracy: 61.11%
Auc: 85.19%
F1Score: 72.00%

Sentiment Predictions
---------------------
Sentiment: Please refrain from adding nonsense to Wikipedia. | Prediction: Positive
Sentiment: He is the best, and the article should say that. | Prediction: Positive

Note, evaluation metrics values have also changed.

(I've run the code that is in the dotnet/samples repo)

It's not clear from the release notes what might have caused the observed change.

The used trainer is FastTreeBinaryClassifier. Its history shows mostly doc changes with some API update changes.

One more guess is that this commit might have introduced different behavior.

@OliaG do you know who might explain the observed difference in the tutorial output?

pkulikov avatar Aug 15 '18 16:08 pkulikov

@GalOshri, or @sfilipi, any insight on this?

JRAlexander avatar Aug 15 '18 16:08 JRAlexander

This is likely due to the datasets being very small so random fluctuations can cause large differences in metrics (the 5% difference in accuracy just means that 1 out of the 18 examples in the test data flipped).

The other factor is that the tree parameters ({ NumLeaves = 5, NumTrees = 5, MinDocumentsInLeafs = 2 }) are very small which limits the performance of the trees. When I switch to default parameters, the AUC matches between 0.3 and 0.4. The accuracy is still different but only corresponds to one example's prediction being flipped.

I tried the same pipeline on a much larger dataset and the AUC/accuracy differed by around 0.3% (which likely is still due to the relatively small tree parameters and current inability to set a random seed).

GalOshri avatar Aug 15 '18 20:08 GalOshri

@GalOshri

This is likely due to the datasets being very small so random fluctuations can cause large differences in metrics

Is it possible to produce such random fluctuations running against the fixed version of the Microsoft.ML? What causes the results be different in versions 0.3 and 0.4, but stay stable within one version?

pkulikov avatar Aug 15 '18 21:08 pkulikov

@GalOshri the code uses TextFeaturizer that seems to have been influenced by dotnet/machinelearning#548 (am I correct here?). So, two sets of numerical features produced by 0.3 and 0.4 versions might be different. Thus, trained models differ. Is my understanding correct?

pkulikov avatar Aug 15 '18 21:08 pkulikov

Good point. It seems like the implementation changed which likely affects the predictions. @zeahmed, can you please verify this?

GalOshri avatar Aug 15 '18 22:08 GalOshri

Due the change in https://github.com/dotnet/machinelearning/pull/548, one of the prediction changed.

Previously, it was 12/18 = 0.666666 Now, it is 11/18 = 0.61111

The dataset is so small to make any conclusion. However, @justinormont may help us on this. @justinormont, Do we have benchmarks for it? Can you confirm if the change in TextFeaturizer has adversely effected the benchmarks?

zeahmed avatar Aug 16 '18 00:08 zeahmed

@zeahmed is this file considered as benchmarks? That file was changed as part of dotnet/machinelearning#548 as well.

pkulikov avatar Aug 16 '18 06:08 pkulikov

@pkulikov, no these are just tests. Benchmarks are different.

zeahmed avatar Aug 16 '18 06:08 zeahmed

I get more accurate results with the previous version (0.3.0) ? nothing else changed in my solution (sentiment analysis)

OnlyChildRecords avatar Sep 04 '18 08:09 OnlyChildRecords

I tried running the solution today, it didn't work initially for me with given hyperparameters, but when I changed them to NumLeaves = 50, NumTrees = 50, MinDocumentsInLeafs = 20 , it gave me correct results.

mangeshw avatar Sep 23 '18 00:09 mangeshw

Thanks, @mangeshw. @GalOshri - should I update the tutorial accordingly?

JRAlexander avatar Sep 24 '18 17:09 JRAlexander

Running the sample code provided on GitHub on ML.net 0.5.0 causes predictions to be positive regardless of the sentiment text being provided. I've even used negative texts from the training set, still returns a positive prediction.

However, adding data from the training set to the testing set causes the accuracy to go up in the metrics output, so my theory is there's something wrong within the Predict method only.

eddieysong avatar Sep 27 '18 18:09 eddieysong

Looks like it's just the output displaying "Positive" for negative sentiments and vice versa.. https://github.com/dotnet/samples/pull/329

eddieysong avatar Sep 27 '18 19:09 eddieysong

Microsoft.ML 0.6.0

Accuracy: 94.44% Auc: 98.77% F1Score: 94.74%

Sentiment: Please refrain from adding nonsense to Wikipedia. | Prediction: Positive Sentiment: He is the best, and the article should say that. | Prediction: Negative

sstcvetkov avatar Oct 06 '18 19:10 sstcvetkov

The last code snippet has error: foreach (var item in sentimentsAndPredictions) { Console.WriteLine($"Sentiment: {item.sentiment.SentimentText} | Prediction: {(item.prediction.Sentiment ? "Negative" : "Positive")}"); } Console.WriteLine();

Should be

foreach (var item in sentimentsAndPredictions) { Console.WriteLine($"Sentiment: {item.sentiment.SentimentText} | Prediction: {(item.prediction.Sentiment ? "Positive" : "Negative")}"); } Console.WriteLine();

PredictionModel quality metrics evaluation

Accuracy: 94.44% Auc: 98.77% F1Score: 94.74%

bolajiniy avatar Oct 07 '18 11:10 bolajiniy

@bolajiniy Try taking a look at the training set, it should be pretty obvious that 0 = positive and 1 = negative. Please reference https://github.com/dotnet/samples/pull/329 Let me know if you still believe it to be an error.

eddieysong avatar Oct 08 '18 00:10 eddieysong

Perhaps we should increase the size of the sample. The dataset is currently sized for a unit test; I don't think its small size is valuable for example code. Perhaps we should increase the size of the sample for use in the example. If the same dataset is used in unit tests, we should ensure the runtime of the unit tests are not adversely impacted. The only point of the unit tests are to see if something changed; they are not expected to make useful models.

Similar issues were mentioned in the main repo: https://github.com/dotnet/machinelearning/issues/708#issuecomment-425706329:

Try running on the full-sized dataset: https://aka.ms/tlc-resources/benchmarks/WikiDetoxAnnotated160kRows.tsv

The wikipedia-detox-250-line-data.tsv dataset is a 250 row sample of the original 160k rows. Training on this small of a sample won't create a useful model.

If someone wants to try a run on the full dataset, this would give the upper bound for how well a specific pipeline (transforms+learner) will perform on the dataset. Running on any small sample of the dataset will do worse (plus noise). We could find an optimal trade-off between sample size (which determines runtime) and output accuracy. This would let us pick a more optimal size dataset for the example.

justinormont avatar Oct 08 '18 04:10 justinormont

tried the full dataset on v0.6.0

Accuracy: 50.00 % Auc: 50.00 % F1Score: NaN

Sentiment Predictions

Sentiment: Please refrain from adding nonsense to Wikipedia. | Prediction: Positive Sentiment: He is the best, and the article should say that. | Prediction: Positive

Hayko-1 avatar Oct 12 '18 09:10 Hayko-1