/// <summary> /// Main method to run the crowdsourcing experiments presented in Simpson et.al (WWW15). /// </summary> public static void Main() { var data = Datum.LoadData(Path.Combine("Data", "weatherTweets.tsv.gz")); // Run model and get results var VocabularyOnSubData = ResultsWords.BuildVocabularyOnSubdata((List <Datum>)data); BCCWords model = new BCCWords(); ResultsWords resultsWords = new ResultsWords(data, VocabularyOnSubData); DataMappingWords mapping = resultsWords.Mapping as DataMappingWords; if (mapping != null) { resultsWords = new ResultsWords(data, VocabularyOnSubData); resultsWords.RunBCCWords("BCCwords", data, data, model, Results.RunMode.ClearResults, true); } using (var writer = new StreamWriter(Console.OpenStandardOutput())) { resultsWords.WriteResults(writer, false, false, false, true); } Console.WriteLine("Done. Press enter to exit."); Console.ReadLine(); }
/// <summary> /// Runs the majority vote method on the data. /// </summary> /// <param name="modelName"></param> /// <param name="data">The data</param> /// <param name="mode"></param> /// <param name="calculateAccuracy">Compute the accuracy (true).</param> /// <param name="fullData"></param> /// <param name="model"></param> /// <param name="useMajorityVote"></param> /// <param name="useRandomLabel"></param> /// <returns>The updated results</returns> public void RunBCCWords(string modelName, IList <Datum> data, IList <Datum> fullData, BCCWords model, RunMode mode, bool calculateAccuracy, bool useMajorityVote = false, bool useRandomLabel = false) { DataMappingWords MappingWords = null; if (FullMapping == null) { FullMapping = new DataMapping(fullData); } if (Mapping == null) { // Build vocabulary Console.Write("Building vocabulary..."); Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); string[] corpus = data.Select(d => d.BodyText).Distinct().ToArray(); Vocabulary = BuildVocabularyFromCorpus(corpus); Console.WriteLine("done. Elapsed time: {0}", stopwatch.Elapsed); // Build data mapping this.Mapping = new DataMappingWords(data, MappingWords.Vocabulary); MappingWords = Mapping as DataMappingWords; this.GoldLabels = MappingWords.GetGoldLabelsPerTaskId(); } MappingWords = Mapping as DataMappingWords; int[] trueLabels = null; if (useMajorityVote) { if (MappingWords != null) { var majorityLabel = MappingWords.GetMajorityVotesPerTaskId(data); trueLabels = Util.ArrayInit(FullMapping.TaskCount, i => majorityLabel.ContainsKey(Mapping.TaskIndexToId[i]) ? (int)majorityLabel[Mapping.TaskIndexToId[i]] : Rand.Int(Mapping.LabelMin, Mapping.LabelMax + 1)); data = MappingWords.BuildDataFromAssignedLabels(majorityLabel, data); } } if (useRandomLabel) { var randomLabels = MappingWords.GetRandomLabelPerTaskId(data); data = MappingWords.BuildDataFromAssignedLabels(randomLabels, data); } var labelsPerWorkerIndex = MappingWords.GetLabelsPerWorkerIndex(data); var taskIndicesPerWorkerIndex = MappingWords.GetTaskIndicesPerWorkerIndex(data); // Create model ClearResults(); model.CreateModel(MappingWords.TaskCount, MappingWords.LabelCount, MappingWords.WordCount); // Run model inference BCCWordsPosteriors posteriors = model.InferPosteriors(labelsPerWorkerIndex, taskIndicesPerWorkerIndex, MappingWords.WordIndicesPerTaskIndex, MappingWords.WordCountsPerTaskIndex, trueLabels); // Update results UpdateResults(posteriors, mode); // Compute accuracy if (calculateAccuracy) { UpdateAccuracy(); } }