Skip to content
This repository was archived by the owner on Nov 22, 2022. It is now read-only.

fixes weight tying bug #704

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions pytext/models/language_models/lmlstm.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,12 @@ def from_config(cls, config: Config, tensorizers: Dict[str, Tensorizer]):
out_dim=len(labels),
)
if config.tied_weights:
decoder.get_decoder()[0].weight = embedding.weight
if decoder.get_decoder()[0][-1].weight.size() != embedding.weight.size():
raise ValueError(
"Embedding dimension must be same as representation "
"dimensions when using tied weights"
)
decoder.get_decoder()[0][-1].weight = embedding.weight
output_layer = create_module(config.output_layer, labels=labels)
return cls(
embedding=embedding,
Expand Down Expand Up @@ -213,7 +218,7 @@ def __init__(
self._states: Optional[Tuple] = None

def arrange_model_inputs(self, tensor_dict):
tokens, seq_lens = tensor_dict["tokens"]
tokens, seq_lens, _ = tensor_dict["tokens"]
# Omit last token because it won't have a corresponding target
return (tokens[:, 0:-1].contiguous(), seq_lens - 1)

Expand Down