Giter VIP home page Giter VIP logo

neuro-comma's Introduction

Neuro-comma

This library was developed with the idea to help us to create punctuation restoration models to memorize trained parameters, data, training visualization, etc. The Library doesn't use any high-level frameworks, such as PyTorch-lightning or Keras, to reduce the level entry threshold.

Feel free to fork this repo and edit model or dataset classes for your purposes.

Prerequirements

  • Python 3.9 for training
  • Docker for production

Why development environment is Python 3.9 if production environment in Dockerfile is 3.8?

  • Our team always uses the latest version and features of Python. We started with Python 3.9, but realized, that there is no FastAPI image for Python 3.9. There is several PRs in image repositories, but no response from maintainers. So we decided to change code which we use in production to work with the 3.8 version of Python. In some functions we have 3.9 code, but we still use them, these functions are needed only for development purposes.

Installation

  • Option 1:
    pip install -U pip wheel setuptools
    pip install -r requirements.txt
  • Option 2:
    sh scripts/installation.sh

Python module usage

Production usage

  • Choose model from releases section
  • Checkout to release tag!
  • Download and unzip model
  • Run docker-compose
    docker-compose up -d
  • Stop container
    docker-compose down

Model training

Model training from scratch:

python src/train.py \
    --model-name repunct-model \
    --pretrained-model DeepPavlov/rubert-base-cased-sentence \
    --targets O COMMA PERIOD \
    --train-data data/repunct/train \
    --val-data data/repunct/test \
    --test-data data/repunct/test \
    --store-best-weights \
    --epoch 7 \
    --batch-size 4 \
    --augment-rate 0.15 \
    --labml \
    --seed 1 \
    --cuda 

Fine-tuning already trained model. Add --fine-tune argument, this will load params from repunct-model and apply them to training function. This will create new subdirectory with {model-name}_ft name in models/ directory. Source model will be untouched.

python src/train.py \
    --model-name repunct-model \
    --fine-tune \
    --targets O COMMA PERIOD \
    --train-data data/repunct/train \
    --val-data data/repunct/test \
    --test-data data/repunct/test \
    --store-best-weights \
    --epoch 3 \
    --batch-size 4 \
    --labml \
    --seed 1 \
    --cuda 

In some cases you want to resume training (computer crashed, light blinked, etc.). This will resume training from last model checkpoint (saved weight). Just add --resume argument.

python src/train.py \
    --model-name repunct-model \
    --resume \
    --pretrained-model DeepPavlov/rubert-base-cased-sentence \
    --targets O COMMA PERIOD \
    --train-data data/repunct/train \
    --val-data data/repunct/test \
    --test-data data/repunct/test \
    --store-best-weights \
    --epoch 4 \
    --batch-size 4 \
    --augment-rate 0.15 \
    --labml \
    --seed 1 \
    --cuda 

More examples here

How it works

Before inserting raw text into model it should be tokenized. Library handle it with BaseDataset.parse_tokens

Model architecture is pretty easy and straight forward:

Model architecture

Credits

Our article on habr.ru

This repository contains code (which was edited for production purposes) from xashru/punctuation-restoration.

Special thanks to @akvarats

neuro-comma's People

Contributors

sviperm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

neuro-comma's Issues

Docker and Windows 10

Microsoft Windows [Version 10.0.19045.4291]
(c) Корпорация Майкрософт (Microsoft Corporation). Все права защищены.

C:\Users\admin>cd C:\znaki\sviperm_neuro-comma\p9

C:\znaki\sviperm_neuro-comma\p9>C:\python39\python -m venv myenv

C:\znaki\sviperm_neuro-comma\p9>myenv\Scripts\activate

(myenv) C:\znaki\sviperm_neuro-comma\p9>sh scripts/installation.sh
'sh' is not recognized as an internal or external command,
operable program or batch file.

(myenv) C:\znaki\sviperm_neuro-comma\p9>cd C:\znaki\sviperm_neuro-comma\p9\neuro-comma\scripts

(myenv) C:\znaki\sviperm_neuro-comma\p9\neuro-comma\scripts>installation.sh

(myenv) C:\znaki\sviperm_neuro-comma\p9\neuro-comma\scripts>docker-compose up -d
Traceback (most recent call last):
File "docker\api\client.py", line 214, in _retrieve_server_version
File "docker\api\daemon.py", line 181, in version
File "docker\utils\decorators.py", line 46, in inner
File "docker\api\client.py", line 237, in _get
File "requests\sessions.py", line 543, in get
File "requests\sessions.py", line 530, in request
File "requests\sessions.py", line 643, in send
File "requests\adapters.py", line 439, in send
File "urllib3\connectionpool.py", line 670, in urlopen
File "urllib3\connectionpool.py", line 392, in _make_request
File "http\client.py", line 1255, in request
File "http\client.py", line 1301, in _send_request
File "http\client.py", line 1250, in endheaders
File "http\client.py", line 1010, in _send_output
File "http\client.py", line 950, in send
File "docker\transport\npipeconn.py", line 32, in connect
File "docker\transport\npipesocket.py", line 23, in wrapped
File "docker\transport\npipesocket.py", line 72, in connect
File "docker\transport\npipesocket.py", line 52, in connect
pywintypes.error: (2, 'CreateFile', 'Не удается найти указанный файл.')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "docker-compose", line 3, in
File "compose\cli\main.py", line 81, in main
File "compose\cli\main.py", line 200, in perform_command
File "compose\cli\command.py", line 60, in project_from_options
File "compose\cli\command.py", line 152, in get_project
File "compose\cli\docker_client.py", line 41, in get_client
File "compose\cli\docker_client.py", line 170, in docker_client
File "docker\api\client.py", line 197, in init
File "docker\api\client.py", line 221, in _retrieve_server_version
docker.errors.DockerException: Error while fetching server API version: (2, 'CreateFile', 'Не удается найти указанный файл.')
[9900] Failed to execute script docker-compose

(myenv) C:\znaki\sviperm_neuro-comma\p9\neuro-comma\scripts>

Cuda vs cpu

Hello.
I'm trying to train neuro-comma and my pc doesn't have cuda avaiable. How can I change it to cpu?

Using pretrained model withought doker

Hello

On the main page of the project there are two variants of usage - either to train from scratch (with our own data) or to fine tune.
How can I use your your model with your pretrained weights?

Проблема с запросом к модели

Привет, подскажите пожалуйста, как делать запросы к модели?
Поднял докер согласно инструкции, контейнер слушает на 8001 порту.

Когда делаю запрос через curl, возвращает ошибку

$ cat test.sh

curl -X 'POST' \
  'http://localhost:8001/' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
  "data": "Сделать модель восстановления знаков препинания у текста который будет получен с помощью Speech-to-Text сервиса"
}'
$ bash test.sh
Internal Server Error

По адресу localhost:8001/docs отображается документация по запросам к модели, поэтому я предполагаю, что докер поставился успешно.

Code problems

Hello, maybe I don't understand something, but you have ":=" in your code at 46 line of 'neuro_comma/src/neuro_comma/dataset.py' and at another file, that I can't remember now, and this things trows me an errors. Is it really mistakes or I'm doing smth wrong?

Api question

Sorry? but i donif find API docs. I started container. how i can add my input.txt file and output?
Thank you

P.s. what STT do you use?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.