transform

transform

class hanlp.common.transform.VocabDict(*args, **kwargs)[source]

A dict holding hanlp.common.vocab.Vocab instances. When used as a transform, it transforms the field corresponding to each hanlp.common.vocab.Vocab into indices.

Parameters
load_vocabs(save_dir, filename='vocabs.json', vocab_cls=<class 'hanlp.common.vocab.Vocab'>)[source]

Load vocabularies from a directory.

Parameters
  • save_dir – The directory to load vocabularies.

  • filename – The name for vocabularies.

lock()[source]

Lock each vocab.

put(**kwargs)[source]

Put names and corresponding hanlp.common.vocab.Vocab instances into self.

Parameters

**kwargs – Names and corresponding hanlp.common.vocab.Vocab instances.

save_vocabs(save_dir, filename='vocabs.json')[source]

Save vocabularies to a directory.

Parameters
  • save_dir – The directory to save vocabularies.

  • filename – The name for vocabularies.

summary(logger: Optional[logging.Logger] = None)[source]

Log a summary of vocabs using a given logger.

Parameters

logger – The logger to use.

unlock()[source]

Unlock each vocab.