public void ExtendDatabaseWithArticle(LabeledArticle article) { Annotation annotation = _processor.Annotate(article.Article); HashSet <string> persons = NLPCoreHelper.GetPersons(annotation); HashSet <string> organizations = NLPCoreHelper.GetOrganizations(annotation); HashSet <string> locations = NLPCoreHelper.GetLocation(annotation); HashSet <string> sportSpecificWords = NLPCoreHelper.GetOccurence(annotation, _sportSpecificWords); foreach (string person in persons) { PersonOccurenceDatabase.AddWord(person, article.Category); } foreach (string organization in organizations) { OrganizationOccurenceDatabase.AddWord(organization, article.Category); } foreach (string location in locations) { LocationsOccurenceDatabase.AddWord(location, article.Category); } foreach (string sportSpecificWord in sportSpecificWords) { SportSpecificWordsOccurenceDatabase.AddWord(sportSpecificWord, article.Category); } }
public double TrainClassifierWithArticle(LabeledArticle article) { double[] input = GetRawFeatures(article.Article); double[] output = GetOutput(article); double error = _teacher.Run(input, output); Console.WriteLine(error); return(error); }
public double CalculateError(LabeledArticle article) { double[] input = GetRawFeatures(article.Article); double[] output = _classifier.Compute(input); double sum = output.Sum(); for (int i = 0; i < output.Length; i++) { output[i] /= sum; } double[] correct = GetOutput(article); double error = 0; for (int i = 0; i < output.Length; i++) { error += Math.Abs(output[i] - correct[i]); } return(error); }
private double[] GetOutput(LabeledArticle article) { double[] output = new double[_categoriesCount]; output[_categoryIndex[article.Category]] = 1; return(output); }