Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Docs/add nnlm docs #5

Merged
merged 2 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@


## [Unreleased]


### Added
- Add NNLM model
3 changes: 3 additions & 0 deletions docs/models/nnlm.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# NNLM

::: toynlp.nnlm.model
30 changes: 30 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ copyright: Copyright © 2025 Xiangzhuang Shen
# Page tree
nav:
- Home: index.md
- Models:
- NNLM: models/nnlm.md
- Changelog: changelog.md
- Author's website: https://shenxiangzhuang.github.io/

Expand Down Expand Up @@ -100,3 +102,31 @@ plugins:
bib_file: "docs/references.bib"
csl_file: "docs/ieee.csl"
cite_inline: false
- mkdocstrings:
handlers:
python:
import:
- https://docs.python-requests.org/en/master/objects.inv
- https://docs.python.org/3/objects.inv
- https://mkdocstrings.github.io/objects.inv
- https://mkdocstrings.github.io/griffe/objects.inv
- https://python-markdown.github.io/objects.inv
options:
docstring_style: google
docstring_options:
ignore_init_summary: true
docstring_section_style: spacy
show_docstring_classes: true
show_docstring_attributes: true
heading_level: 2
members_order: source
merge_init_into_class: true
separate_signature: true
show_root_heading: false
show_root_full_path: true
show_signature_annotations: true
signature_crossrefs: true
show_root_members_full_path: true
show_root_toc_entry: true
show_symbol_type_heading: true
show_symbol_type_toc: true
File renamed without changes.
Empty file added toynlp/nnlm/__init__.py
Empty file.
16 changes: 16 additions & 0 deletions toynlp/nnlm/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ def __init__(
self,
config: ModelConfig,
):
"""
The Neural Network Language Model (NNLM) model.

Args:
config: ModelConfig, the model configuration.
"""
super(NNLM, self).__init__()
self.with_direct_connection = config.with_direct_connection
self.with_dropout = config.with_dropout
Expand All @@ -32,6 +38,16 @@ def __init__(
self.dropout = torch.nn.Dropout(config.dropout_rate)

def forward(self, tokens: torch.Tensor) -> torch.Tensor:
"""
Forward pass of the model.

Args:
tokens: torch.Tensor, (batch_size, seq_len-1), the input tokens.

Returns:
torch.Tensor, (batch_size, vocab_size), the logits.

"""
# tokens: (batch_size, seq_len-1) -> x: (batch_size, seq_len-1, embedding_dim)
x = self.C(tokens)
b, _, _ = x.shape
Expand Down
Loading