Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/kefirski/pytorch_NEG_loss

NEG loss implemented in pytorch
https://github.com/kefirski/pytorch_NEG_loss

python pytorch word2vec

Last synced: 3 months ago
JSON representation

NEG loss implemented in pytorch

Awesome Lists containing this project

README

        

# Pytorch Negative Sampling Loss

[Negative Sampling Loss](https://arxiv.org/abs/1310.4546) implemented in [PyTorch](http://www.pytorch.org).

![NEG Loss Equation](images/neg.png)

## Usage

```python
neg_loss = NEG_loss(num_classes, embedding_size)

optimizer = SGD(neg_loss.parameters(), 0.1)

for i in range(num_iterations):
'''
input is [batch_size] shaped tensors of Long type
while target has shape of [batch_size, window_size]
'''
input, target = next_batch(batch_size)

loss = neg_loss(input, target, num_sample)

optimizer.zero_grad()
loss.backward()
optimizer.step()

word_embeddings = neg_loss.input_embeddings()
```