Skip to content

Commit

Permalink
Merge pull request #9 from spraakbanken/fix-names
Browse files Browse the repository at this point in the history
fix names
  • Loading branch information
kod-kristoff authored May 29, 2024
2 parents 90999e2 + b68e41f commit 6c2b2cb
Show file tree
Hide file tree
Showing 10 changed files with 834 additions and 681 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,54 @@ jobs:
- name: make test
run: make test

run-example:
name: ubuntu / 3.8 / run-example / ${{ matrix.example-name }}
strategy:
max-parallel: 4
fail-fast: false
matrix:
example-name:
- sparv-sbx-sentence-sentiment-kb-sent
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
#----------------------------------------------
# ----- setup python -----
#----------------------------------------------
- name: Set up the environment
uses: pdm-project/setup-pdm@v4
id: setup-python
with:
python-version: ${{ env.MINIMUM_PYTHON_VERSION }}


- name: Load cached venv
id: cached-venv
uses: actions/cache@v4
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/pyproject.toml') }}-${{ hashFiles('.github/workflows/ci.yml') }}

- name: Install dependencies
if: steps.cached-venv.outputs.cache-hit != 'true'
run: make install-dev

- name: Run example
run: |
source .venv/bin/activate
cd examples/${{ matrix.example-name }}
echo "" | sparv setup
sparv run
ls -R
# https://github.com/marketplace/actions/alls-green#why used for branch protection checks
test-check:
if: always()
needs:
- coverage
- minimal
- run-example
runs-on: ubuntu-latest
permissions: {}
steps:
Expand Down
34 changes: 34 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: check-yaml
stages: [commit]
- id: check-json
stages: [commit]
- id: check-toml
stages: [commit]
- id: check-merge-conflict
stages: [commit]
- id: check-case-conflict
stages: [commit]
- id: detect-private-key
stages: [commit]
# - id: end-of-file-fixer
- id: check-added-large-files
stages: [commit]
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.4.4
hooks:
# Run the linter.
- id: ruff
# Run the formatter.
- id: ruff-format
- repo: https://github.com/crate-ci/committed
rev: v1.0.20
hooks:
- id: committed
stages: [commit-msg]
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ CHANGELOG.md:
snapshot-update:
${INVENV} pytest --snapshot-update

.PHONY: kb-bert-prepare-release
.PHONY: sparv-sbx-sentence-sentiment-kb-sent-prepare-release
sparv-sbx-sentence-sentiment-kb-sent-prepare-release: sparv-sbx-sentence-sentiment-kb-sent/CHANGELOG.md

.PHONY: sparv-sbx-sentence-sentiment-kb-sent/CHANGELOG.md
Expand Down
3 changes: 3 additions & 0 deletions examples/sparv-sbx-sentence-sentiment-kb-sent/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ metadata:
import:
importer: text_import:parse

sbx_sentence_sentiment_kb_sent:
num_decimals: 3

export:
annotations:
- <sentence>
Expand Down
1,406 changes: 739 additions & 667 deletions pdm.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions sparv-sbx-sentence-sentiment-kb-sent/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

[![CI(release)](https://github.com/spraakbanken/sparv-sbx-sentiment-analysis/actions/workflows/release-sentence-sentiment-kb-sent.yml/badge.svg)](https://github.com/spraakbanken/sparv-sbx-sentiment-analysis/actions/workflows/release-sentence-sentiment-kb-sent.yml)

Plugin for applying bert masking as a [Sparv](https://github.com/spraakbanken/sparv-pipeline) annotation.
Plugin for computing sentence sentiment as a [Sparv](https://github.com/spraakbanken/sparv-pipeline) annotation.

## Install

Expand All @@ -33,15 +33,15 @@ annotation exclusively by adding it as the only annotation to export under `xml_
```yaml
xml_export:
annotations:
- <token>:sbx_sentence_sentiment_kb_sent.sentence-sentiment--kb-bert
- <sentence>:sbx_sentence_sentiment_kb_sent.sentence-sentiment--kb-sent
```
To use it together with other annotations you might add it under `export`:

```yaml
export:
annotations:
- <token>:sbx_sentence_sentiment_kb_sent.sentence-sentiment--kb-bert
- <sentence>:sbx_sentence_sentiment_kb_sent.sentence-sentiment--kb-sent
...
```

Expand Down
7 changes: 2 additions & 5 deletions sparv-sbx-sentence-sentiment-kb-sent/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[project]
name = "sparv-sbx-sentence-sentiment-kb-sent"
version = "0.1.0"
description = "A sparv plugin for computing word neighbours using a BERT model."
description = "A sparv plugin for computing sentence sentiment."
authors = [
{ name = "Språkbanken Text", email = "[email protected]" },
{ name = "Kristoffer Andersson", email = "[email protected]" },
Expand Down Expand Up @@ -55,7 +55,4 @@ allow-direct-references = true


[tool.pdm.dev-dependencies]
dev = [
"pytest>=8.0.0",
"syrupy>=4.6.1",
]
dev = ["pytest>=8.0.0", "syrupy>=4.6.1"]
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from sparv import api as sparv_api # type: ignore [import-untyped]

from sbx_sentence_sentiment_kb_sent.annotations import annotate_sentence_sentiment
from sbx_sentence_sentiment_kb_sent.constants import PROJECT_NAME

__all__ = ["annotate_sentence_sentiment"]

Expand All @@ -11,7 +12,7 @@

__config__ = [
sparv_api.Config(
"sbx_sentence_sentiment_kb_bert.num_decimals",
f"{PROJECT_NAME}.num_decimals",
description="The number of decimals to round the score to",
default=3,
),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""Sparv annotator."""
"""Sparv annotator for sentiment analysis on sentences."""

from sparv import api as sparv_api # type: ignore [import-untyped]

from sbx_sentence_sentiment_kb_sent.constants import PROJECT_NAME
from sbx_sentence_sentiment_kb_sent.sentiment_analyzer import SentimentAnalyzer

logger = sparv_api.get_logger(__name__)
Expand All @@ -10,20 +11,20 @@
@sparv_api.annotator("Sentiment analysis of sentences", language=["swe"])
def annotate_sentence_sentiment(
out_sentence_sentiment: sparv_api.Output = sparv_api.Output(
"<sentence>:sbx_sentence_sentiment_kb_sent.sentence-sentiment--kb-sent",
f"<sentence>:{PROJECT_NAME}.sentence-sentiment--kb-sent",
# cls="sbx_sentence_sentiment_kb_sent",
description="Sentiment analysis of sentence with KBLab/robust-swedish-sentiment-multiclass", # noqa: E501
),
word: sparv_api.Annotation = sparv_api.Annotation("<token:word>"),
sentence: sparv_api.Annotation = sparv_api.Annotation("<sentence>"),
num_decimals_str: str = sparv_api.Config("sbx_sentence_sentiment_kb_sent.num_decimals"),
num_decimals_str: str = sparv_api.Config(f"{PROJECT_NAME}.num_decimals"),
) -> None:
"""Sentiment analysis of sentence with KBLab/robust-swedish-sentiment-multiclass."""
try:
num_decimals = int(num_decimals_str)
except ValueError as exc:
raise sparv_api.SparvErrorMessage(
f"'sbx_word_prediction_kb_bert.num_decimals' must contain an 'int' got: '{num_decimals_str}'" # noqa: E501
f"'{PROJECT_NAME}.num_decimals' must contain an 'int' got: '{num_decimals_str}'"
) from exc
sentences, _orphans = sentence.get_children(word)
token_word = list(word.read())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"""Constants used in this project."""

PROJECT_NAME: str = "sbx_sentence_sentiment_kb_sent"

0 comments on commit 6c2b2cb

Please sign in to comment.