embedding

embedding

class hanlp.layers.embeddings.embedding.Embedding[source]

Base class for embedding builders.

module(**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(**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.

class hanlp.layers.embeddings.embedding.ConcatModuleList(*modules: Optional[Iterable[torch.nn.modules.module.Module]], dropout=None)[source]

A nn.ModuleList to bundle several embeddings modules.

Parameters
  • *modules – Embedding layers.

  • dropout – Dropout applied on the concatenated embedding.

forward(batch: dict, **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.embedding.EmbeddingList(*embeddings_, embeddings: Optional[dict] = None, dropout=None)[source]

An embedding builder to bundle several embedding builders.

Parameters
  • *embeddings_ – A list of embedding builders.

  • embeddings – Deserialization for a dict of embedding builders.

  • dropout – Dropout applied on the concatenated embedding.

module(**kwargs)[source]

Build a module for this embedding.

Parameters

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

Returns

A module.

transform(**kwargs)[source]

Build a transform function for this embedding.

Parameters

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

Returns

A transform function.