https://github.com/centre-for-humanities-computing/glovpy
Package for interfacing Stanford's C GloVe implementation from Python.
Science Score: 13.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
○.zenodo.json file
-
○DOI references
-
○Academic publication links
-
○Academic email domains
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (10.5%) to scientific vocabulary
Repository
Package for interfacing Stanford's C GloVe implementation from Python.
Basic Info
- Host: GitHub
- Owner: centre-for-humanities-computing
- License: mit
- Language: Python
- Default Branch: main
- Size: 14.6 KB
Statistics
- Stars: 3
- Watchers: 0
- Forks: 0
- Open Issues: 0
- Releases: 0
Metadata Files
README.md
glovpy
Package for interfacing Stanford's C GloVe implementation from Python.
Installation
Install glovpy from PyPI:
bash
pip install glovpy
Additionally the first time you import glopy it will build GloVe from scratch on your system.
Requirements
We highly recommend that you use a Unix-based system, preferably a variant of Debian.
The package needs git, make and a C compiler (clang or gcc) installed.
Otherwise the implementation is as barebones as it gets, only the standard library and gensim are being used (gensim only for producing KeyedVectors).
Example Usage
Here's a quick example of how to train GloVe on 20newsgroups using Gensim's tokenizer.
```python from gensim.utils import tokenize from sklearn.datasets import fetch_20newsgroups
from glovpy import GloVe
texts = fetch_20newsgroups().data corpus = [list(tokenize(text, lowercase=True, deacc=True)) for text in texts]
model = GloVe(vector_size=25) model.train(corpus)
for word, similarity in model.wv.most_similar("god"): print(f"{word}, sim: {similarity}") ```
| word | similarity | |------------|---------------| | existence | 0.9156746864 | | jesus | 0.8746870756 | | lord | 0.8555182219 | | christ | 0.8517201543 | | bless | 0.8298447728 | | faith | 0.8237065077 | | saying | 0.8204566240 | | therefore | 0.8177698255 | | desires | 0.8094088435 | | telling | 0.8083973527 |
API Reference
class glovpy.GloVe(vector_size, window_size, symmetric, distance_weighting, alpha, min_count, iter, initial_learning_rate, threads, memory)
Wrapper around the original C implementation of GloVe.
Parameters
| Parameter | Type | Description | Default | |------------------------|-------------------|--------------------------------------------------------------------------------------------------|------------------| | vectorsize | _int | Number of dimensions the trained word vectors should have. | 50 | | windowsize | _int | Number of context words to the left (and to the right, if symmetric is True). | 15 | | alpha | float | Parameter in exponent of weighting function; default 0.75 | 0.75 | | symmetric | bool | If true, both future and past words will be used as context, otherwise only past words will be used. | True | | distanceweighting | _bool | If False, do not weight cooccurrence count by distance between words. If True (default), weight the cooccurrence count by inverse of distance between the target word and the context word. | True | | mincount | _int | Minimum number of times a token has to appear to be kept in the vocabulary. | 5 | | iter | int | Number of training iterations. | 25 | | initiallearningrate | float | Initial learning rate for training. | 0.05 | | threads | int | Number of threads to use for training. | 8 | | memory | float | Soft limit for memory consumption, in GB. (based on simple heuristic, so not extremely accurate) | 4.0 |
Attributes
| Name | Type | Description | |------|------|-------------| | wv | KeyedVectors | Token embeddings in the form of Gensim keyed vectors. |
Methods
glovpy.GloVe.train(tokens)
Train the model on a stream of texts.
| Parameter | Type | Description | |-----------|------|-------------| | tokens | Iterable[list[str]] | Stream of documents in the form of lists of tokens. The stream has to be reusable, as the model needs at least two passes over the corpus. |
glovpy.utils.reusable(gen_func)
Function decorator that turns your generator function into an iterator, thereby making it reusable. You can use this if you want to reuse a generator function so that multiple passes can be made.
Parameters
| Parameter | Type | Description | |-----------|----------|----------------------------------------------| | genfunc | _Callable | Generator function that you want to be reusable. |
Returns
| Returns | Type | Description | |-----------|----------|--------------------------------------------------------| | multigen | _Callable | Iterator class wrapping the generator function. |
Example usage
Here's how to stream a very long file line by line in a reusable manner.
```python from gensim.utils import tokenize from glovpy.utils import reusable from glovpy import GloVe
@reusable def streamlines(): with open("verylongtextfile.txt") as f: for line in f: yield list(tokenize(line))
model = GloVe() model.train(stream_lines()) ```
Owner
- Name: Center for Humanities Computing Aarhus
- Login: centre-for-humanities-computing
- Kind: organization
- Email: chcaa@cas.au.dk
- Location: Aarhus, Denmark
- Website: https://chc.au.dk/
- Repositories: 130
- Profile: https://github.com/centre-for-humanities-computing
GitHub Events
Total
- Watch event: 1
Last Year
- Watch event: 1
Issues and Pull Requests
Last synced: over 1 year ago
All Time
- Total issues: 0
- Total pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Total issue authors: 0
- Total pull request authors: 0
- Average comments per issue: 0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 0
- Pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Issue authors: 0
- Pull request authors: 0
- Average comments per issue: 0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels
Dependencies
- gensim ^4.3.0
- python ^3.9