CONTENTS OF THIS FILE
- Introduction
- Setup
- Getting started
- Examples
INTRODUCTION
A simple iterator that reads conll and conllu files (https://universaldependencies.org/format.html) without keeping them in memory. It can iterate over words, sentences, or documents.
SETUP
pip install git+https://github.com/nicolaCirillo/conll_iterator.git
GETTING STARTED
from conll_iterator import ConllIterator
from tqdm import tqdm
sentences = ConllIterator('sample/sample_corpus.conllu',
fields=['form', 'upos'],
mode='sentences',
join_char='/')
for s in tqdm(sentences):
# do something
EXAMPLES
Training word2vec
from gensim.models import Word2Vec
from tqdm import tqdm
from conll_iterator import ConllIterator
sentences = ConllIterator('sample/sample_corpus.conllu', fields=['lemma', 'upos'], mode='sentences', join_char='/')
w2v_parameters = {'vector_size': 25, 'window': 5, 'min_count': 1, 'sg': 1, 'epochs': 15}
model = Word2Vec(tqdm(sentences), workers=5, **w2v_parameters)
model.save('sample_w2v')
word_vectors = model.wv
similar = list(zip(*word_vectors.most_similar('Pecorino/PROPN')[:10]))[0]
print("Most similar words to Pecorino/PROPN:")
print(similar)
Keyword extraction via tf-idf
from itertools import chain
from collections import Counter
docs = ConllIterator('sample/sample_corpus.conllu', fields=['lemma', 'upos'], lower=['lemma'], mode='documents')
doc_tf = list()
df = Counter()
allowed_pos = ['NOUN', 'PROPN','VERB', 'ADJ']
for d in docs:
tokens = list(chain(*d))
tokens = [t[0] for t in tokens if t[1] in allowed_pos]
tf = Counter(tokens)
df.update(set(tokens))
doc_tf.append(tf)
doc_keywords = list()
for d in doc_tf:
doc_tfidf = [(w, d[w]/df[w]) for w in d]
doc_tfidf = sorted(doc_tfidf, key=lambda x:x[1], reverse=True)
doc_keywords.append(list(zip(*doc_tfidf[:10]))[0])
for i, k in enumerate(doc_keywords[:20]):
print('keywords of doc {}:'.format(i+1), '; '.join(k))
Metadata
Release files for conll-iterator 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| conll_iterator-0.0.1.tar.gz | 6.2 kB | Without provenance | Details for conll_iterator-0.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| conll_iterator-0.0.1-py3-none-any.whl | Python 3 | none | any | Details for conll_iterator-0.0.1-py3-none-any.whl |
Total release size: 12.9 kB
Release files / conll_iterator-0.0.1.tar.gz
| Download URL | conll_iterator-0.0.1.tar.gz |
|---|---|
| Size | 6.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b769fcc9ce0188784cdd1279da9095287be8d14adb3781d4f880c2c2520030ae
|
|
BLAKE2b-256 checksum How to use checksums |
62a704f51ac27102e6a7b1a769d2f69fe21c8d3971ab641f0c6a2245228ef452
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.2
|
Release files / conll_iterator-0.0.1-py3-none-any.whl
| Download URL | conll_iterator-0.0.1-py3-none-any.whl |
|---|---|
| Size | 6.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
44a9697c87c05f56b946b0f6f086e6332e45e3d99cce77caa7a5019deef7a7e6
|
|
BLAKE2b-256 checksum How to use checksums |
db3895fe0c594ba17be517e51d228340224b1d957f73347dcc6453442d0cc962
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.2
|
Security for conll-iterator 0.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.