Skip to content

Commit b9830e1

Browse files
committed
Merge branch 'release/v0.1.1'
2 parents 40df6c2 + 843837a commit b9830e1

32 files changed

Lines changed: 1130 additions & 170 deletions

.github/workflows/mkdocs.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Build Document by Mkdocs
2+
on:
3+
push:
4+
branches:
5+
- develop
6+
7+
jobs:
8+
build:
9+
name: Deploy docs
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout develop
13+
uses: actions/checkout@v2
14+
- name: Set up Python 3.7
15+
uses: actions/setup-python@v2
16+
with:
17+
python-version: 3.7
18+
- name: Install dependencies
19+
run: python -m pip install -e '.[docs]'
20+
- name: Build
21+
run: mkdocs build
22+
- name: Deploy
23+
uses: peaceiris/actions-gh-pages@v3
24+
with:
25+
github_token: ${{ secrets.GITHUB_TOKEN }}
26+
publish_dir: ./site
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# This workflows will upload a Python Package using Twine when a release is created
2+
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries
3+
4+
name: Upload Python Package
5+
6+
on:
7+
release:
8+
types: [created]
9+
10+
jobs:
11+
deploy:
12+
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- uses: actions/checkout@v2
17+
- name: Set up Python
18+
uses: actions/setup-python@v2
19+
with:
20+
python-version: '3.7'
21+
- name: Install dependencies
22+
run: |
23+
python -m pip install --upgrade pip
24+
python -m pip install setuptools wheel twine
25+
- name: Build and publish
26+
env:
27+
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
28+
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
29+
run: |
30+
python setup.py sdist bdist_wheel
31+
twine upload dist/*

.github/workflows/unit-tests.yml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: unit-tests
1+
name: Unit Tests
22

33
on: [push]
44

@@ -7,17 +7,21 @@ jobs:
77

88
runs-on: ubuntu-latest
99

10+
strategy:
11+
matrix:
12+
python-version: ["3.7"]
13+
1014
steps:
11-
- uses: actions/checkout@v1
12-
- name: Set up Python 3.7
13-
uses: actions/setup-python@v1
15+
- uses: actions/checkout@v2
16+
- name: Set up Python ${{ matrix.python-version }}
17+
uses: actions/setup-python@v2
1418
with:
15-
python-version: 3.7
19+
python-version: "${{ matrix.python-version }}"
1620
- name: Install dependencies
1721
run: |
1822
python -m pip install --upgrade pip
1923
python -m pip install torch
20-
python -m pip install -e '.[dev]'
24+
python -m pip install -e '.[dev, ctx]'
2125
- name: Test with pytest
2226
run: |
2327
python -m pytest tests

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,3 +640,4 @@ GitHub.sublime-settings
640640
*.ptx
641641
*.cubin
642642
*.fatbin
643+
!/site/

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# TorchGlyph
22

3-
[![Actions Status](https://github.com/speedcell4/torchglyph/workflows/unit-tests/badge.svg)](https://github.com/speedcell4/torchglyph/actions)
3+
![Unit Tests](https://github.com/speedcell4/torchglyph/workflows/Unit%20Tests/badge.svg)
4+
![Upload Python Package](https://github.com/speedcell4/torchglyph/workflows/Upload%20Python%20Package/badge.svg)
45

56
## Requirements
67

docs/index.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Welcome to TorchGlyph
2+
3+
Data Processor Combinators for Natural Language Processing
4+
5+
[![Actions Status](https://github.com/speedcell4/torchglyph/workflows/unit-tests/badge.svg)](https://github.com/speedcell4/torchglyph/actions)
6+
7+
## Installation
8+
9+
Simply run this command in your terminal,
10+
11+
```bash
12+
pip install torchglyph
13+
```
14+
15+
## Quickstart
16+
17+
The atomic data processor of TorchGlyph is called `Proc`. Compose operator `+` is provided to produce complex `Proc` by composing two simple `Proc`s.
18+
19+
```python
20+
ToLower() + ReplaceDigits(repl_token='<digits>')
21+
```
22+
23+
Composed `Proc`s act like data `Pipe`lines, where raw textual data is processed incrementally. According to the stages, they are roughly categorized into four-groups:
24+
25+
+ `pre` for processing *before* building vocabulary;
26+
+ `vocab` for building and updating *vocabulary*;
27+
+ `post` for precessing *after* building vocabulary;
28+
+ `batch` for collating examples to build *batches*.
29+
30+
Defining the `Pipe`s of your dataset is the first step to build a dataset, you can build it from scratch,
31+
32+
```python
33+
class PackedIdxSeqPipe(Pipe):
34+
def __init__(self, device, dtype=torch.long) -> None:
35+
super(PackedIdxSeqPipe, self).__init__(
36+
pre=None,
37+
vocab=None,
38+
post=ToTensor(dtype=dtype),
39+
batch=PackSeq(enforce_sorted=False) + ToDevice(device=device),
40+
)
41+
```
42+
43+
or you can simply manipulate existing `Pipe`s by calling `.with_` method.
44+
45+
```python
46+
class PackedTokSeqPipe(PackedIdxSeqPipe):
47+
def __init__(self, device, unk_token, special_tokens=(),
48+
threshold=THRESHOLD, dtype=torch.long) -> None:
49+
super(PackedTokSeqPipe, self).__init__(device=device, dtype=dtype)
50+
self.with_(
51+
pre=UpdateCounter(),
52+
vocab=[
53+
BuildVocab(unk_token=unk_token, pad_token=None,
54+
special_tokens=special_tokens),
55+
StatsVocab(threshold=threshold),
56+
],
57+
post=Numbering() + ...,
58+
)
59+
```

mkdocs.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
site_name: TorchGlyph
2+
nav:
3+
- Home: index.md
4+
theme: alabaster

setup.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
from setuptools import setup, find_packages
22

3-
with open('README.md', 'r', encoding='utf-8') as fp:
4-
long_description = fp.read()
3+
name = 'torchglyph'
54

65
setup(
7-
name='torchglyph',
8-
version='0.1.0',
9-
packages=find_packages(),
10-
url='https://github.com/speedcell4/torchglyph',
6+
name=name,
7+
version='0.1.1',
8+
packages=[package for package in find_packages() if package.startswith(name)],
9+
url=f'https://speedcell4.github.io/torchglyph',
1110
license='MIT',
1211
author='speedcell4',
1312
author_email='speedcell4@gmail.com',
1413
description='Data Processor Combinators for Natural Language Processing',
15-
long_description=long_description,
1614
install_requires=[
1715
'tqdm',
1816
'numpy',
@@ -23,5 +21,14 @@
2321
'pytest',
2422
'hypothesis',
2523
],
24+
'ctx': [
25+
'transformers',
26+
'allennlp',
27+
'elmoformanylangs',
28+
],
29+
'docs': [
30+
'mkdocs',
31+
'mkdocs-alabaster',
32+
]
2633
}
2734
)
Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,29 @@
1-
from torchglyph.datasets.sequential_labeling import CoNLL2000Chunking, CoNLL2003NER
1+
from torchglyph.datasets import CoNLL2000Chunking, CoNLL2003NER
2+
from torchglyph.datasets import SemEval2010T1NERCatalan, SemEval2010T1NERSpanish
23

34

4-
def test_conll2000_chunking() -> None:
5-
train, test = CoNLL2000Chunking.new(batch_size=1, word_dim=None)
6-
assert len(train) == 8936
7-
assert len(test) == 2012
5+
def test_conll2000_chunking():
6+
train, test = CoNLL2000Chunking.new(batch_size=1, word_dim=None, remove_missing=True)
7+
assert len(train.dataset) == 8936
8+
assert len(test.dataset) == 2012
89

910

10-
def test_conll2003_ner() -> None:
11-
train, dev, test = CoNLL2003NER.new(batch_size=1, word_dim=None)
12-
assert len(train) == 14987
13-
assert len(dev) == 3466
14-
assert len(test) == 3684
11+
def test_conll2003_ner():
12+
train, dev, test = CoNLL2003NER.new(batch_size=1, word_dim=None, remove_missing=True)
13+
assert len(train.dataset) == 14987
14+
assert len(dev.dataset) == 3466
15+
assert len(test.dataset) == 3684
16+
17+
18+
def test_semeval2010_catalan():
19+
train, dev, test = SemEval2010T1NERCatalan.new(batch_size=1, word_dim=None, remove_missing=True)
20+
assert len(train.dataset) == 8709
21+
assert len(dev.dataset) == 1445
22+
assert len(test.dataset) == 1698
23+
24+
25+
def test_semeval2010_spanish():
26+
train, dev, test = SemEval2010T1NERSpanish.new(batch_size=1, word_dim=None, remove_missing=True)
27+
assert len(train.dataset) == 9022
28+
assert len(dev.dataset) == 1419
29+
assert len(test.dataset) == 1705

tests/test_datasets/test_text_classification.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33

44
def test_agnews():
5-
train, test = AgNews.new(batch_size=1, word_dim=None)
5+
train, test = AgNews.new(batch_size=1, word_dim=None, remove_missing=True)
66
assert len(train) == 120000
77
assert len(test) == 7600

0 commit comments

Comments
 (0)