SenticGCNEmbeddingModel

class SenticGCNEmbeddingModel(config: sgnlp.models.sentic_gcn.config.SenticGCNEmbeddingConfig)[source]

The SenticGCN Embedding Model used to generate embeddings for model inputs. By default, the embeddings are generated from the glove.840B.300d embeddings.

This class inherits from SenticGCNEmbeddingPreTrainedModel for weights initalization and utility functions from transformers PreTrainedModel class.

This class can also be constructed via the SenticGCNEmbeddingModel.build_embedding_matrix class method.

Parameters

config (SenticGCNEmbeddingConfig) – Model configuration class with all parameters required for the model. Initializing with a config file does not load the weights associated with the model, only the configuration. Use the from_pretrained method to load the model weights.

classmethod build_embedding_model(word_vec_file_path: str, vocab: Dict[str, int], embed_dim: int = 300)[source]

This class method is a helper method to construct the embedding model from a file containing word vectors (i.e. GloVe) and a vocab dictionary.

Parameters
  • word_vec_file_path (str) – file path to the word vectors

  • vocab (Dict[str, int]) – vocab dictionary consisting of words as key and index as values

  • embed_dim (int, optional) – the embedding dimension. Defaults to 300.

Returns

return an instance of SenticGCNEmbeddingModel

Return type

SenticGCNEmbeddingModel

forward(token_ids: torch.Tensor)torch.Tensor[source]

Encode input token ids using word embedding.

Parameters

token_ids (torch.Tensor) – Tensor of token ids with shape [batch_size, num_words]

Returns

return Tensor of embeddings with shape (batch_size, num_words, embed_dim)

Return type

torch.Tensor