/// <summary>
        /// Creates events for the provided sample.
        /// </summary>
        /// <param name="sample">The sample the sample for which training <see cref="T:Event"/>s are be created.</param>
        /// <returns>The events enumerator.</returns>
        protected override IEnumerator <Event> CreateEvents(NameSample sample)
        {
            if (sample.ClearAdaptiveData)
            {
                contextGenerator.ClearAdaptiveData();
            }

            var tokens   = new string[sample.Sentence.Length];
            var outcomes = codec.Encode(sample.Names, tokens.Length);

            additionalContextFeatureGenerator.SetCurrentContext(sample.AdditionalContext);

            for (int i = 0; i < sample.Sentence.Length; i++)
            {
                tokens[i] = sample.Sentence[i];
            }

            return(GenerateEvents(tokens, outcomes, contextGenerator).GetEnumerator());
        }
Example #2
0
        /// <summary>
        /// Generates name tags for the given sequence, typically a sentence, returning token spans for any identified names.
        /// </summary>
        /// <param name="tokens">An array of the tokens or words of the sequence, typically a sentence.</param>
        /// <param name="additionalContext">Features which are based on context outside of the sentence but which should also be used.</param>
        /// <returns>An array of spans for each of the names identified.</returns>
        public Span[] Find(string[] tokens, string[][] additionalContext)
        {
            additionalContextFeatureGenerator.SetCurrentContext(additionalContext);

            bestSequence = model.BestSequence(tokens,
                                              Array.ConvertAll(additionalContext, input => (object)input),
                                              contextGenerator,
                                              sequenceValidator);

            var outcomes = bestSequence.Outcomes.ToArray();

            contextGenerator.UpdateAdaptiveData(tokens, outcomes);

            var spans = sequenceCodec.Decode(outcomes);

            var probs = Probs(spans);

            for (var i = 0; i < probs.Length; i++)
            {
                spans[i].Probability = probs[i];
            }

            return(spans);
        }