char_rnn

class hanlp.layers.embeddings.char_rnn.CharRNN(field, vocab_size, embed: Union[int, torch.nn.modules.sparse.Embedding], hidden_size)[source]

Character level RNN embedding module.

Parameters
  • field – The field in samples this encoder will work on.

  • vocab_size – The size of character vocab.

  • embed – An Embedding object or the feature size to create an Embedding object.

  • hidden_size – The hidden size of RNNs.

forward(batch, mask, **kwargs)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class hanlp.layers.embeddings.char_rnn.CharRNNEmbedding(field, embed, hidden_size, max_word_length=None)[source]

Character level RNN embedding module builder.

Parameters
  • field – The field in samples this encoder will work on.

  • embed – An Embedding object or the feature size to create an Embedding object.

  • hidden_size – The hidden size of RNNs.

  • max_word_length – Character sequence longer than max_word_length will be truncated.

module(vocabs: hanlp.common.transform.VocabDict, **kwargs) → Optional[torch.nn.modules.module.Module][source]

Build a module for this embedding.

Parameters

**kwargs – Containing vocabs, training etc. Not finalized for now.

Returns

A module.

transform(vocabs: hanlp.common.transform.VocabDict, **kwargs) → Optional[Callable][source]

Build a transform function for this embedding.

Parameters

**kwargs – Containing vocabs, training etc. Not finalized for now.

Returns

A transform function.