Train POS Tagger.
556300
def train(ctx, output, corpus, clusters):
    """"""
    click.echo('chemdataextractor.pos.train')
    click.echo('Output: %s' % output)
    click.echo('Corpus: %s' % corpus)
    click.echo('Clusters: %s' % clusters)

    wsj_sents = []
    genia_sents = []

    if corpus == 'wsj' or corpus == 'wsj+genia':
        wsj_sents = list(wsj_training.tagged_sents())
        # For WSJ, remove all tokens with -NONE- tag
        for i, wsj_sent in enumerate(wsj_sents):
            wsj_sents[i] = [t for t in wsj_sent if not t[1] == '-NONE-']

    if corpus == 'genia' or corpus == 'wsj+genia':
        genia_sents = list(genia_training.tagged_sents())
        # Translate GENIA
        for i, genia_sent in enumerate(genia_sents):
            for j, (token, tag) in enumerate(genia_sent):
                if tag == '(':
                    genia_sents[i][j] = (token, '-LRB-')  # ( to -RLB- (also do for evaluation)
                elif tag == ')':
                    genia_sents[i][j] = (token, '-RRB-')  # ) to -RRB- (also do for evaluation)
                elif tag == 'CT':
                    genia_sents[i][j] = (token, 'DT')  # Typo?
                elif tag == 'XT':
                    genia_sents[i][j] = (token, 'DT')  # Typo?
                elif tag == '-':
                    genia_sents[i][j] = (token, ':')  # Single hyphen character for dash
                elif tag == 'N':
                    genia_sents[i][j] = (token, 'NN')  # Typo?
                elif tag == 'PP':
                    genia_sents[i][j] = (token, 'PRP')  # Typo?
                elif tag == '' and token == ')':
                    genia_sents[i][j] = (token, '-RRB-')  # Typo?
                elif tag == '' and token == 'IFN-gamma':
                    genia_sents[i][j] = (token, 'NN')  # Typo?
                elif '|' in tag:
                    genia_sents[i][j] = (token, tag.split('|')[0])  # If contains |, choose first part
            # Filter any tags not in the allowed tagset (Shouldn't be any left anyway)
            genia_sents[i] = [t for t in genia_sent if t[1] in TAGS]

    if corpus == 'wsj':
        training_corpus = wsj_sents
    elif corpus == 'genia':
        training_corpus = genia_sents
    elif corpus == 'wsj+genia':
        training_corpus = wsj_sents + genia_sents
    else:
        raise click.ClickException('Invalid corpus')

    tagger = ChemCrfPosTagger(clusters=clusters)
    tagger.train(training_corpus, output)
299152
def train(self, root=''):
        

        self.trainer = Train(root=root)
        corpus = self.trainer.get_corpus()

        # Show loaded Languages
        #print 'Lang Set: ' + ' '.join(train.get_lang_set())

        for item in corpus:
            self.lm.add_doc(doc_id=item[0], doc_terms=self._readfile(item[1]))

        # Save training timestamp
        self.training_timestamp = self.trainer.get_last_modified()
898679
def pos(self, element = None):
		'''  '''

		tags = []
		if element:
			if re.search('[\w|\s]+ [m|f]\.', element, re.U):
				tags.append('NN')
			if '[VERB]' in element:
				tags.append('VB')
			if 'adj.' in element and re.search('([\w|\s]+, [\w|\s]+)', element, re.U):
				tags.append('JJ')
		else:
			for element in self.elements:
				if element.startswith(self.word):
					tags += self.pos(element)
		return list(set(tags))
1327488
def tags(self):
        """"""
        tags = self.pos_tags
        for i, tag in enumerate(self.ner_tags):
            if tag is not None:
                tags[i] = tag
        return tags
119487
def pos(self, element = None):
		'''  '''

		tags = []
		if element:
			if element.startswith(('de ', 'het ', 'het/de', 'de/het')) and not re.search('\[[\w|\s][\w|\s]+\]', element.split('\r\n')[0], re.U):
				tags.append('NN')
			if re.search('[\w|\s|/]+ \| [\w|\s|/]+ - [\w|\s|/]+', element, re.U):
				tags.append('VB')
			if re.search('[\w|\s]+ \| [\w|\s]+', element, re.U):
				tags.append('JJ')
			return tags
		else:
			for element in self.elements:
				if self.word in unicode(element):
					tag = self.pos(element)
					if tag:
						return tag
919280
def tag(tagger, args):
  """"""
  for l in args.input:
    words = l.strip().split()
    line_annotations = [u"{:<16}{:<5}".format(w,p) for w, p in tagger.annotate(words)]
    _print(u"\n".join(line_annotations))
    _print(u"")
642182
def train(self, input, label):
        

        assert self._mode == MpsGraphMode.Train
        assert input.shape == self._ishape
        assert label.shape == self._oshape

        input_array = MpsFloatArray(input)
        label_array = MpsFloatArray(label)
        result_handle = _ctypes.c_void_p()
        status_code = self._LIB.TCMPSTrainGraph(
            self.handle, input_array.handle, label_array.handle,
            _ctypes.byref(result_handle))

        assert status_code == 0, "Error calling TCMPSTrainGraph"
        assert result_handle, "TCMPSTrainGraph unexpectedly returned NULL pointer"

        result = MpsFloatArray(result_handle)

        # Output from training should be a one-dimensional array of loss values,
        # one per example in the batch.
        assert result.shape() == (self._oshape[0],)

        return result
705290
def train_all(ctx, output):
    """"""
    click.echo('chemdataextractor.pos.train_all')
    click.echo('Output: %s' % output)
    ctx.invoke(train, output='%s_wsj_nocluster.pickle' % output, corpus='wsj', clusters=False)
    ctx.invoke(train, output='%s_wsj.pickle' % output, corpus='wsj', clusters=True)
    ctx.invoke(train, output='%s_genia_nocluster.pickle' % output, corpus='genia', clusters=False)
    ctx.invoke(train, output='%s_genia.pickle' % output, corpus='genia', clusters=True)
    ctx.invoke(train, output='%s_wsj_genia_nocluster.pickle' % output, corpus='wsj+genia', clusters=False)
    ctx.invoke(train, output='%s_wsj_genia.pickle' % output, corpus='wsj+genia', clusters=True)
1224759
def train(self, s, path="spelling.txt"):
        
        model = {}
        for w in re.findall("[a-z]+", s.lower()):
            model[w] = w in model and model[w] + 1 or 1
        model = ("%s %s" % (k, v) for k, v in sorted(model.items()))
        model = "\n".join(model)
        f = open(path, "w")
        f.write(model)
        f.close()
745719
def train_cb(self, param):
        
        if param.nbatch % self.frequent == 0:
            self._process_batch(param, 'train')
821503
void buildPT_T() {
    int numTags = tagIndex.size();
    m_TT = new double[numTags][numTags];
    m_T = new double[numTags];
    double[] tmp = new double[numTags];
    for (IntTaggedWord word : words) {
      double tot = 0.0;
      for (int t = 0; t < numTags; t++) {
        IntTaggedWord iTW = new IntTaggedWord(word.word, t);
        tmp[t] = seenCounter.getCount(iTW);
        tot += tmp[t];
      }
      if (tot < 10) {
        continue;
      }
      for (int t = 0; t < numTags; t++) {
        for (int t2 = 0; t2 < numTags; t2++) {
          if (tmp[t2] > 0.0) {
            double c = tmp[t] / tot;
            m_T[t] += c;
            m_TT[t2][t] += c;
          }
        }
      }
    }
  }
505032
def tag_labels(self):
        """"""
        if not self.is_tagged(ANALYSIS):
            self.tag_analysis()
        if self.__ner_tagger is None:
            self.__ner_tagger = load_default_ner_tagger()
        self.__ner_tagger.tag_document(self)
        return self
716412
def tag(self, *tag, **kwtags):
        """"""
        if not tag:
            pass
        elif len(tag) == 1 and isinstance(tag[0], dict):
            self._meta.update(tag[0])
        else:
            raise TypeError('Tags must be provided as key-word arguments or '
                            'a dictionary')
        self._meta.update(kwtags)
        return self
1092689
def _SkipGroup(buffer, pos, end):
  """"""

  while 1:
    (tag_bytes, pos) = ReadTag(buffer, pos)
    new_pos = SkipField(buffer, pos, end, tag_bytes)
    if new_pos == -1:
      return pos
    pos = new_pos
20701
def consume(self):
        """"""
        if self.match:
            self.pos = self.match.end()
            if self.match.group()[-1] == '\n':
                self._update_prefix()
            self.match = None
1259900
def train_token(self, word, count):
        
        if word not in self.tokens:
            self.tokens[word] = 0

        self.tokens[word] += count
        self.tally += count
536156
def train(klass, text)
      th = TextHash.new(text)
      th.each { |word, count|
        @storage.incr_word_count klass, word, count
        yield word, count if block_given?
      }
      @storage.incr_total_word_count klass, th.word_count
      doccount = (text.kind_of? Array) ? text.length : 1
      @storage.incr_doc_count klass, doccount
      @classnames << klass unless @classnames.include? klass
      # cache is now dirty of these vars
      @doc_count_totals = nil
      @vocab_sizes = nil
      th
    end