示例#1
0
 public MaximumEntropyPOSTagger(int beamSize, MaxEntropyModel_Interface model, IPosContextGenerator contextGenerator, Interfaces.PosLookupList dictionary)
 {
     mBeamSize         = beamSize;
     mPosModel         = model;
     mContextGenerator = contextGenerator;
     Beam        = new PosBeamSearch(this, mBeamSize, contextGenerator, model);
     mDictionary = dictionary;
 }
示例#2
0
        /// <summary>
        /// Creates new search object.
        /// </summary>
        /// <param name="size">
        /// The size of the beam (k).
        /// </param>
        /// <param name="contextGenerator">
        /// the context generator for the model.
        /// </param>
        /// <param name="model">
        /// the model for assigning probabilities to the sequence outcomes.
        /// </param>
        /// <param name="cacheSize">
        /// size of the cache to use for performance.
        /// </param>
        public BeamSearch(int size, IBeamSearchContextGenerator contextGenerator, MaxEntropyModel_Interface model, int cacheSize)
        {
            Size             = size;
            ContextGenerator = contextGenerator;
            Model            = model;

            mProbabilities = new double[model.OutcomeCount];
            if (cacheSize > 0)
            {
                mContextsCache = new Cache(cacheSize);
            }
        }
示例#3
0
        public virtual void LocalEvaluate(MaxEntropyModel_Interface posModel, System.IO.StreamReader reader, out double accuracy, out double sentenceAccuracy)
        {
            mPosModel = posModel;
            float total = 0, correct = 0, sentences = 0, sentencesCorrect = 0;

            System.IO.StreamReader sentenceReader = new System.IO.StreamReader(reader.BaseStream, System.Text.Encoding.UTF7);
            string line;

            while ((object)(line = sentenceReader.ReadLine()) != null)
            {
                sentences++;
                Util.Pair <ArrayList, ArrayList> annotatedPair = Interfaces.PosEventReader.ConvertAnnotatedString(line);
                ArrayList words    = annotatedPair.FirstValue;
                ArrayList outcomes = annotatedPair.SecondValue;
                ArrayList tags     = new ArrayList(Beam.BestSequence(words, null).Outcomes);

                int  count        = 0;
                bool isSentenceOK = true;
                for (System.Collections.IEnumerator tagIndex = tags.GetEnumerator(); tagIndex.MoveNext(); count++)
                {
                    total++;
                    string tag = (string)tagIndex.Current;
                    if (tag == (string)outcomes[count])
                    {
                        correct++;
                    }
                    else
                    {
                        isSentenceOK = false;
                    }
                }
                if (isSentenceOK)
                {
                    sentencesCorrect++;
                }
            }

            accuracy         = correct / total;
            sentenceAccuracy = sentencesCorrect / sentences;
        }
示例#4
0
 /// <summary>
 /// Creates a new name finder with the specified model and context generator.
 /// </summary>
 /// <param name="model">
 /// The model to be used to find names.
 /// </param>
 /// <param name="contextGenerator">
 /// The context generator to be used with this name finder.
 /// </param>
 /// <param name="beamSize">
 /// The size of the beam to be used in decoding this model.
 /// </param>
 public MaximumEntropyNameFinder(MaxEntropyModel_Interface model, Interfaces.INameContextGenerator contextGenerator, int beamSize)
 {
     mModel            = model;
     mContextGenerator = contextGenerator;
     mBeam             = new NameBeamSearch(this, beamSize, contextGenerator, model, beamSize);
 }
示例#5
0
 /// <summary>
 /// Creates a new name finder with the specified model and context generator.
 /// </summary>
 /// <param name="model">
 /// The model to be used to find names.
 /// </param>
 /// <param name="contextGenerator">
 /// The context generator to be used with this name finder.
 /// </param>
 public MaximumEntropyNameFinder(MaxEntropyModel_Interface model, Interfaces.INameContextGenerator contextGenerator) : this(model, contextGenerator, 10)
 {
 }
示例#6
0
 /// <summary>
 /// Creates a new name finder with the specified model.
 /// </summary>
 /// <param name="model">
 /// The model to be used to find names.
 /// </param>
 public MaximumEntropyNameFinder(MaxEntropyModel_Interface model) : this(model, new Interfaces.DefaultNameContextGenerator(10), 10)
 {
 }
示例#7
0
 /// <summary>
 /// Creates a beam seach of the specified size using the specified model with the specified context generator.
 /// </summary>
 /// <param name="nameFinder">
 /// The associated MaximumEntropyNameFinder instance.
 /// </param>
 /// <param name="size">
 /// The size of the beam.
 /// </param>
 /// <param name="contextGenerator">
 /// The context generator used with the specified model.
 /// </param>
 /// <param name="model">
 /// The model used to determine names.
 /// </param>
 /// <param name="beamSize">
 /// The size of the beam to use in searching.
 /// </param>
 public NameBeamSearch(MaximumEntropyNameFinder nameFinder, int size, Interfaces.INameContextGenerator contextGenerator, MaxEntropyModel_Interface model, int beamSize) : base(size, contextGenerator, model, beamSize)
 {
     mNameFinder = nameFinder;
 }
示例#8
0
 public PosBeamSearch(MaximumEntropyPOSTagger posTagger, int size, Util.IBeamSearchContextGenerator contextGenerator, MaxEntropyModel_Interface model, int cacheSize) : base(size, contextGenerator, model, cacheSize)
 {
     mMaxentPosTagger = posTagger;
 }
示例#9
0
 public MaximumEntropyPOSTagger(MaxEntropyModel_Interface model, IPosContextGenerator contextGenerator, Interfaces.PosLookupList dictionary) : this(mDefaultBeamSize, model, contextGenerator, dictionary)
 {
 }
示例#10
0
 public MaximumEntropyPOSTagger(MaxEntropyModel_Interface model, IPosContextGenerator contextGenerator) : this(mDefaultBeamSize, model, contextGenerator, null)
 {
 }
示例#11
0
 // Constructors
 public MaximumEntropyPOSTagger(MaxEntropyModel_Interface model) : this(model, new POS_ContextGenerator())
 {
 }
示例#12
0
 /// <summary>
 /// Creates new search object.
 /// </summary>
 /// <param name="size">
 /// The size of the beam (k).
 /// </param>
 /// <param name="contextGenerator">
 /// the context generator for the model.
 /// </param>
 /// <param name="model">
 /// the model for assigning probabilities to the sequence outcomes.
 /// </param>
 public BeamSearch(int size, IBeamSearchContextGenerator contextGenerator, MaxEntropyModel_Interface model) : this(size, contextGenerator, model, 0)
 {
 }
示例#13
0
		/// <summary>
		/// Creates a chunker using the specified model and context generator.
		/// </summary>
		/// <param name="model">
		/// The maximum entropy model for this chunker.
		/// </param>
		/// <param name="contextGenerator">
		/// The context generator to be used by the specified model.
		/// </param>
		public MaximumEntropyChunker(MaxEntropyModel_Interface model, IChunkerContextGenerator contextGenerator):this(model, contextGenerator, 10)
		{
		}
示例#14
0
		/// <summary>
		/// Creates a chunker using the specified model.
		/// </summary>
		/// <param name="model">
		/// The maximum entropy model for this chunker.
		/// </param>
		public MaximumEntropyChunker(MaxEntropyModel_Interface model):this(model, new DefaultChunkerContextGenerator(), 10)
		{
		}
示例#15
0
			public ChunkBeamSearch(MaximumEntropyChunker maxentChunker, int size, IChunkerContextGenerator contextGenerator, MaxEntropyModel_Interface model):base(size, contextGenerator, model)
			{
				mMaxentChunker = maxentChunker;
			}
示例#16
0
		/// <summary>
		/// Creates a chunker using the specified model and context generator and decodes the
		/// model using a beam search of the specified size.
		/// </summary>
		/// <param name="model">
		/// The maximum entropy model for this chunker.
		/// </param>
		/// <param name="contextGenerator">
		/// The context generator to be used by the specified model.
		/// </param>
		/// <param name="beamSize">
		/// The size of the beam that should be used when decoding sequences.
		/// </param>
		public MaximumEntropyChunker(MaxEntropyModel_Interface model, IChunkerContextGenerator contextGenerator, int beamSize)
		{
			mBeam = new ChunkBeamSearch(this, beamSize, contextGenerator, model);
			mModel = model;
		}