Exemple #1
0
        /// <summary>
        /// get requery text.
        /// </summary>
        /// <param name="qnastatus">qnastatus.</param>
        /// <param name="activityText">activity text.</param>
        /// <param name="activeLearningdata">activeleraning data.</param>
        /// <returns></returns>
        public static string GetRequery(ShowQnAResultState qnastatus, string activityText, ActiveLearningDTO activeLearningdata = null)
        {
            string requery = null;

            if (qnastatus.QnaAnswer.Options != null && qnastatus.QnaAnswer.Options.Count != 0)
            {
                foreach (var promptoption in qnastatus.QnaAnswer.Options)
                {
                    if (promptoption.Option.Equals(activityText, StringComparison.CurrentCultureIgnoreCase))
                    {
                        requery = string.IsNullOrEmpty(promptoption.Requery) ? promptoption.Option : promptoption.Requery;

                        // call train API if active learning
                        if (qnastatus.ActiveLearningAnswer == true && activeLearningdata != null)
                        {
                            qnastatus.ActiveLearningAnswer = false;
                            activeLearningdata.qnaId       = promptoption.QnAId;
                            ActiveLearning.CallTrainApi(activeLearningdata);
                            qnastatus.ActiveLearningUserQuestion = null;
                        }

                        break;
                    }
                }
            }
            else
            {
                requery = string.IsNullOrEmpty(qnastatus.QnaAnswer.Requery) ? null : qnastatus.QnaAnswer.Requery;
            }

            return(requery);
        }
Exemple #2
0
        /// <summary>
        /// Runs the active learning experiment presented in Venanzi et.al (WWW14) on a single data set.
        /// </summary>
        /// <param name="dataSet">The data.</param>
        /// <param name="runType">The model run type.</param>
        /// <param name="taskSelectionMethod">The method for selecting tasks (Random / Entropy).</param>
        /// <param name="model">The model instance.</param>
        /// <param name="communityCount">The number of communities (only for CBCC).</param>
        public static void RunHCOMPActiveLearning(string dataSet, RunType runType, TaskSelectionMethod taskSelectionMethod, int InitialNumLabelsPerTask, BCC model, int communityCount = 4)
        {
            var    data      = Datum.LoadData(@"Data/" + dataSet + ".csv");
            string modelName = Program.GetModelName(dataSet, runType, taskSelectionMethod, WorkerSelectionMethod.RandomWorker);

            //initial Number of Label Per Task
            //int initialNumLabelsPerTask = 1;
            int initialNumLabelsPerTask = InitialNumLabelsPerTask;

            ActiveLearning.RunActiveLearning(data, modelName, runType, model, taskSelectionMethod, WorkerSelectionMethod.RandomWorker, ResultsDir, communityCount, initialNumLabelsPerTask);
        }
Exemple #3
0
        private QueryResult HandleActiveLearning(QueryResult[] response, ShowQnAResultState qnaStatus, string userQuestion)
        {
            var filteredResponse   = response.Where(answer => answer.Score > Constants.DefaultThreshold).ToList();
            var responseCandidates = ActiveLearning.GetLowScoreVariation(filteredResponse);

            if (responseCandidates.Count > 1)
            {
                var activeLearningResponse = ActiveLearning.GenerateResponse(responseCandidates);
                qnaStatus.ActiveLearningAnswer       = true;
                qnaStatus.ActiveLearningUserQuestion = userQuestion;
                return(activeLearningResponse);
            }

            return(responseCandidates[0]);
        }
Exemple #4
0
        /// <summary>
        /// Background Thread for running the active learning experiment
        /// <param name="worker"></param>
        /// <param name="e"></param>
        public void RunParallelActiveLearning(
            System.ComponentModel.BackgroundWorker worker,
            System.ComponentModel.DoWorkEventArgs e)
        {
            //Create a state of the Thread
            CurrentParallelState currentState = new CurrentParallelState();

            //Set setting in the experimentSetting Class
            int totalNumberOfModels = GetNumberOfExperiemntModels();

            //Clear previous results
            ActiveLearning.ResetParallelAccuracyList(totalNumberOfModels);

            //obtain the accuracy list reference
            accuracyArrayOfAllExperimentModels = ActiveLearning.accuracyArray;

            //The RunTypes that have Worker Confusion Matrices
            RunType[] runTypesHaveWorkerMatrices = { RunType.DawidSkene, RunType.BCC, RunType.CBCC };

            //Set the models selected in the setting pane
            string[]                currentModelNames             = new string[totalNumberOfModels];
            RunType[]               currentRunTypes               = new RunType[totalNumberOfModels];
            TaskSelectionMethod[]   currentTaskSelectionMethods   = new TaskSelectionMethod[totalNumberOfModels];
            WorkerSelectionMethod[] currentWorkerSelectionMethods = new WorkerSelectionMethod[totalNumberOfModels];
            BCC[] currentBCCModels = new BCC[totalNumberOfModels];

            //for each ExperimentModel, set runTypeArray, taskSelectionMethodArray, workerSelectionMethodArray...
            for (int i = 0; i < totalNumberOfModels; i++)
            {
                ExperimentModel currentExperimentModel = GetExperimentModel(i);
                RunType         currentRunType         = currentExperimentModel.runType;
                currentRunTypes[i] = currentRunType;

                //set the task selection method
                currentTaskSelectionMethods[i] = currentExperimentModel.taskSelectionMethod;

                //Add into worker selection method array if the runType can have worker selection
                if (runTypesHaveWorkerMatrices.Contains(currentRunType))
                {
                    currentWorkerSelectionMethods[i] = currentExperimentModel.WorkerSelectionMethod;

                    //Add corresponding model
                    //if the RunType is BCC, add into BCC model array
                    if (currentRunType == RunType.BCC)
                    {
                        currentBCCModels[i] = new BCC();
                    }//CBCC Model
                    else if (currentRunType == RunType.CBCC)
                    {
                        CBCC currentBCCmodel = new CBCC();
                        currentBCCModels[i] = currentBCCmodel;
                    }
                } //end if the runType has worker confusion matrices
            }     //end for

            currentModelNames = currentModelNames.Select((s, i) => CrowdsourcingModels.Program.GetModelName(currentDataset.GetDataSetNameWithoutExtension(), currentRunTypes[i])).ToArray();

            //run RunParallelActiveLearning in the ActiveLearning
            ActiveLearning.RunParallelActiveLearning(currentDataset.LoadData(), currentModelNames, currentRunTypes,
                                                     currentBCCModels, currentTaskSelectionMethods, currentWorkerSelectionMethods,
                                                     communityCount, numberOfLabellingRound);

            currentState.isRunningComplete = true;
            Debug.WriteLine("RunParallelActiveLearning Complete");
            //isSimulationComplete = true;
            //worker.ReportProgress(0, currentState);
        }//end function RunParallelActiveLearning