Skip to content

Commit b8d31eb

Browse files
committed
init
0 parents  commit b8d31eb

File tree

16 files changed

+910
-0
lines changed

16 files changed

+910
-0
lines changed

.github/FUNDING.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# These are supported funding model platforms
2+
3+
github: [sloev]
4+
custom: ['https://www.buymeacoffee.com/sloev']

.github/onix.webp

7.18 KB
Binary file not shown.

.github/workflows/test.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: test
2+
3+
on: [push]
4+
5+
jobs:
6+
build:
7+
8+
runs-on: ubuntu-latest
9+
strategy:
10+
matrix:
11+
python-version: ["3.8", "3.9", "3.10"]
12+
13+
steps:
14+
- uses: actions/checkout@v3
15+
- name: Set up Python ${{ matrix.python-version }}
16+
uses: actions/setup-python@v4
17+
with:
18+
python-version: ${{ matrix.python-version }}
19+
- name: Install dependencies
20+
run: |
21+
python -m pip install --upgrade pip setuptools wheel
22+
pip install -e ".[dev]"
23+
- name: Lint with black
24+
run: |
25+
black --version
26+
black --check .
27+
- name: Test with pytest
28+
run: |
29+
pytest --version
30+
python -m spacy download en_core_web_sm
31+
pytest -vvl

.gitignore

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
.DS_Store
2+
# Byte-compiled / optimized / DLL files
3+
__pycache__/
4+
*.py[cod]
5+
*$py.class
6+
7+
# C extensions
8+
*.so
9+
10+
# Distribution / packaging
11+
.Python
12+
build/
13+
develop-eggs/
14+
dist/
15+
downloads/
16+
eggs/
17+
.eggs/
18+
lib/
19+
lib64/
20+
parts/
21+
sdist/
22+
var/
23+
wheels/
24+
share/python-wheels/
25+
*.egg-info/
26+
.installed.cfg
27+
*.egg
28+
MANIFEST
29+
30+
# PyInstaller
31+
# Usually these files are written by a python script from a template
32+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
33+
*.manifest
34+
*.spec
35+
36+
# Installer logs
37+
pip-log.txt
38+
pip-delete-this-directory.txt
39+
40+
# Unit test / coverage reports
41+
htmlcov/
42+
.tox/
43+
.nox/
44+
.coverage
45+
.coverage.*
46+
.cache
47+
nosetests.xml
48+
coverage.xml
49+
*.cover
50+
*.py,cover
51+
.hypothesis/
52+
.pytest_cache/
53+
cover/
54+
55+
# Translations
56+
*.mo
57+
*.pot
58+
59+
# Django stuff:
60+
*.log
61+
local_settings.py
62+
db.sqlite3
63+
db.sqlite3-journal
64+
65+
# Flask stuff:
66+
instance/
67+
.webassets-cache
68+
69+
# Scrapy stuff:
70+
.scrapy
71+
72+
# Sphinx documentation
73+
docs/_build/
74+
75+
# PyBuilder
76+
.pybuilder/
77+
target/
78+
79+
# Jupyter Notebook
80+
.ipynb_checkpoints
81+
82+
# IPython
83+
profile_default/
84+
ipython_config.py
85+
86+
# pyenv
87+
# For a library or package, you might want to ignore these files since the code is
88+
# intended to run in multiple environments; otherwise, check them in:
89+
# .python-version
90+
91+
# pipenv
92+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
93+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
94+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
95+
# install all needed dependencies.
96+
#Pipfile.lock
97+
98+
# poetry
99+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
100+
# This is especially recommended for binary packages to ensure reproducibility, and is more
101+
# commonly ignored for libraries.
102+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
103+
#poetry.lock
104+
105+
# pdm
106+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
107+
#pdm.lock
108+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
109+
# in version control.
110+
# https://pdm.fming.dev/#use-with-ide
111+
.pdm.toml
112+
113+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
114+
__pypackages__/
115+
116+
# Celery stuff
117+
celerybeat-schedule
118+
celerybeat.pid
119+
120+
# SageMath parsed files
121+
*.sage.py
122+
123+
# Environments
124+
.env
125+
.venv
126+
env/
127+
venv/
128+
ENV/
129+
env.bak/
130+
venv.bak/
131+
132+
# Spyder project settings
133+
.spyderproject
134+
.spyproject
135+
136+
# Rope project settings
137+
.ropeproject
138+
139+
# mkdocs documentation
140+
/site
141+
142+
# mypy
143+
.mypy_cache/
144+
.dmypy.json
145+
dmypy.json
146+
147+
# Pyre type checker
148+
.pyre/
149+
150+
# pytype static type analyzer
151+
.pytype/
152+
153+
# Cython debug symbols
154+
cython_debug/
155+
156+
# PyCharm
157+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
158+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
159+
# and can be added to the global gitignore or merged into this file. For a more nuclear
160+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
161+
#.idea/

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 sloev / Johannes Valbjørn
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
![spacy syllables](https://raw.githubusercontent.com/sloev/sentimental-onix/master/.github/onix.webp) <a href="https://www.buymeacoffee.com/sloev" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/default-pink.png" alt="Buy Me A Coffee" height="51px" width="217px"></a>
2+
3+
![example workflow](https://github.com/sloev/sentimental-onix/actions/workflows/test.yml/badge.svg) [![Latest Version](https://img.shields.io/pypi/v/sentimental-onix.svg)](https://pypi.python.org/pypi/sentimental-onix) [![Python Support](https://img.shields.io/pypi/pyversions/sentimental-onix.svg)](https://pypi.python.org/pypi/sentimental-onix)
4+
5+
# Sentimental Onix
6+
7+
Sentiment Analysis using [onnx](https://github.com/onnx/onnx) for python with a focus on being [spacy](https://github.com/explosion/spaCy) compatible *and EEEEEASY to use*.
8+
9+
**Features**
10+
- [x] English sentiment analysis
11+
- [x] Spacy pipeline component
12+
13+
14+
## Install
15+
16+
```bash
17+
pip install spacy_onnx_sentiment_english
18+
```
19+
20+
## Usage
21+
22+
```python
23+
import spacy
24+
from sentimental_onix import pipeline
25+
26+
nlp = spacy.load("en_core_web_sm")
27+
nlp.add_pipe("sentencizer")
28+
nlp.add_pipe("sentimental_onix", after="sentencizer")
29+
30+
sentences = [
31+
(sent.text, sent._.sentiment)
32+
for doc in nlp.pipe(
33+
[
34+
"i hate pasta on tuesdays",
35+
"i like movies on wednesdays",
36+
"i find your argument ridiculous",
37+
"soda with straws are my favorite",
38+
]
39+
)
40+
for sent in doc.sents
41+
]
42+
43+
assert sentences == [
44+
("i hate pasta on tuesdays", "Negative"),
45+
("i like movies on wednesdays", "Positive"),
46+
("i find your argument ridiculous", "Negative"),
47+
("soda with straws are my favorite", "Positive"),
48+
]
49+
50+
```
51+
52+
## Dev setup / testing
53+
54+
### Install
55+
56+
install the dev package and pyenv versions
57+
58+
```bash
59+
$ pip install -e ".[dev]"
60+
$ python -m spacy download en_core_web_sm
61+
```
62+
63+
### Run tests
64+
65+
```bash
66+
$ black .
67+
$ pytest -vvl
68+
```
69+
70+
71+
### Packaging and publishing
72+
73+
```bash
74+
python3 -m pip install --upgrade build twine
75+
python3 -m build
76+
python3 -m twine upload dist/*
77+
```

pyproject.toml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
[build-system]
2+
requires = ["setuptools"]
3+
build-backend = "setuptools.build_meta"
4+
5+
6+
[project]
7+
name = "sentimental-onix"
8+
version = "0.0.1"
9+
description = "spacy pipeline component for sentiment analysis using onnx"
10+
readme = "README.md"
11+
authors = [{ name = "sloev", email = "[email protected]" }]
12+
license = { file = "LICENSE" }
13+
classifiers = [
14+
"Development Status :: 6 - Mature",
15+
"Intended Audience :: Developers",
16+
"Natural Language :: English",
17+
"Programming Language :: Python :: 3.8",
18+
"Programming Language :: Python :: 3.9",
19+
"Programming Language :: Python :: 3.10",
20+
]
21+
keywords = ["spacy", "onnx", "sentiment", "english", "nlp"]
22+
dependencies = [
23+
"spacy >= 3.0.3",
24+
"onnx >= 1.13.1",
25+
"onnxruntime >= 1.14.1",
26+
"numpy",
27+
]
28+
requires-python = ">=3.8"
29+
30+
[project.scripts]
31+
sentimental_onix = "sentimental_onix.cli:main"
32+
33+
[project.optional-dependencies]
34+
dev = ["black>=23.1.0", "pytest"]
35+
36+
[project.urls]
37+
Homepage = "https://github.com/sloev/sentimental-onix"
38+
39+
[tool.setuptools]
40+
include-package-data = true

sentimental_onix/__init__.py

Whitespace-only changes.

sentimental_onix/cli.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from sentimental_onix import models
2+
3+
def main():
4+
print("main", models.EN_SENTIMENT_DOWNLOAD_TEMPLATE)

sentimental_onix/data/__init__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import os
2+
from importlib.metadata import version
3+
__version__ = version(__package__)
4+
5+
__MODELS_FOLDER_PATH = os.path.dirname(os.path.abspath(__file__))
6+
7+
EN_SENTIMENT_MODEL_PATH = os.path.join(__MODELS_FOLDER_PATH, "en.sentiment.model.onnx")
8+
EN_SENTIMENT_TOKENIZER_PATH = os.path.join(__MODELS_FOLDER_PATH, "en.sentiment.tokenizer.json")
9+
EN_SENTIMENT_DOWNLOAD_TEMPLATE = f"{__version__}"
24.1 MB
Binary file not shown.

sentimental_onix/data/en.sentiment.tokenizer.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

sentimental_onix/models.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import os
2+
from importlib.metadata import version
3+
4+
try:
5+
__version__ = version(__package__)
6+
except:
7+
__version__ = "unknown"
8+
9+
__DATA_FOLDER = os.path.join(os.path.dirname(os.path.abspath(__file__)), "data")
10+
11+
EN_SENTIMENT_MODEL_PATH = os.path.join(__DATA_FOLDER, "en.sentiment.model.onnx")
12+
EN_SENTIMENT_TOKENIZER_PATH = os.path.join(__DATA_FOLDER, "en.sentiment.tokenizer.json")
13+
EN_SENTIMENT_DOWNLOAD_TEMPLATE = f"{__version__}"

0 commit comments

Comments
 (0)