Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V2 #440

Open
wants to merge 170 commits into
base: master
Choose a base branch
from
Open

V2 #440

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
170 commits
Select commit Hold shift + click to select a range
22d3eec
Move default package URL to argosopentech.com
PJ-Finlay Sep 14, 2022
e7dba5a
Remove deprecated load_available_packages
PJ-Finlay Sep 14, 2022
754c833
Remove data_snap dir
PJ-Finlay Sep 15, 2022
c4aafbe
Remove deprecated LibreTranslateTranslation
PJ-Finlay Sep 16, 2022
ef40f4e
Remove deprecated load_installed_languages
PJ-Finlay Sep 16, 2022
13fcab7
remove deprecated load_installed_languages() (#287)
dingedi Sep 17, 2022
c234fcd
Improved Python example
PJ-Finlay Sep 16, 2022
62dd3c5
Backwards compatibility fix
PJ-Finlay Sep 16, 2022
c748e1b
Edit Python example
PJ-Finlay Sep 16, 2022
54ee4a3
Update Python example
PJ-Finlay Sep 17, 2022
34b7eb0
Feature: add sacrebleu script (#290)
dingedi Sep 19, 2022
32a3ef2
Parse source_languages from metadata
PJ-Finlay Sep 25, 2022
64ad850
argostranslate.package v2 updates
PJ-Finlay Sep 25, 2022
4004c74
Update sbd to v2 chunk system
PJ-Finlay Sep 25, 2022
0c5a408
Parse "dependencies" package metadata
PJ-Finlay Sep 25, 2022
1fa8b4c
Update argospm to v2
PJ-Finlay Sep 25, 2022
94313b2
Remove paragraph splitting
PJ-Finlay Sep 25, 2022
8959303
Removed languages.csv
PJ-Finlay Sep 25, 2022
725f38a
Refactor argostranslate.translate for multilingual
PJ-Finlay Sep 28, 2022
c206304
Log as list not tuple
PJ-Finlay Sep 28, 2022
923c712
Update settings to v2
PJ-Finlay Sep 29, 2022
0600493
Refactored settings.py
PJ-Finlay Sep 29, 2022
9d6a8a8
Document argostranslate.settings
PJ-Finlay Sep 29, 2022
7a64d4b
Reorder
PJ-Finlay Sep 29, 2022
d4be9cf
Improve translation logging
PJ-Finlay Sep 29, 2022
e78cf8b
Log as jsonl
PJ-Finlay Sep 29, 2022
e3a0e5a
Add more logging levels
PJ-Finlay Sep 30, 2022
6fcede5
Refactor logging
PJ-Finlay Sep 30, 2022
5202422
Improve JSON logging
PJ-Finlay Sep 30, 2022
69a11ab
Typo fixes
PJ-Finlay Sep 30, 2022
534d358
Improved logging
PJ-Finlay Sep 30, 2022
1058351
Update argostranslate.settings
PJ-Finlay Sep 30, 2022
a72f83b
Update argostranslate.settings
PJ-Finlay Sep 30, 2022
dcb0136
Update ReleaseNotes.md
PJ-Finlay Sep 30, 2022
cd105ef
ReleaseNotes formatting
PJ-Finlay Sep 30, 2022
a93db39
Add repr to argospm list
PJ-Finlay Sep 30, 2022
06535c4
Made settings.is_debug
PJ-Finlay Sep 30, 2022
b938380
Typo fix
PJ-Finlay Sep 30, 2022
a2f0cd2
Applying chunk translations
PJ-Finlay Oct 1, 2022
f7226c2
Seq2Seq input chunking
PJ-Finlay Oct 1, 2022
d92b138
Download package dependencies
PJ-Finlay Oct 6, 2022
027c6f9
Random GUID in download filenames
PJ-Finlay Oct 6, 2022
a987959
Update ReleaseNotes
PJ-Finlay Oct 6, 2022
92fe025
Merge branch 'master' into v2
PJ-Finlay Oct 14, 2022
ef583a7
Merge branch 'master' into v2
PJ-Finlay Oct 14, 2022
b617bd7
Remove stanza
PJ-Finlay Oct 14, 2022
b31fe31
Improve argostranslate.translate imports
PJ-Finlay Oct 16, 2022
ebb4a4f
argostranslate.translate.Hypotheses tweak
PJ-Finlay Oct 16, 2022
9c659c7
Updated apis
PJ-Finlay Oct 16, 2022
30aed85
Updated from LibreTranslate-py
PJ-Finlay Oct 16, 2022
c812150
Update argosopentech.com url
PJ-Finlay Oct 16, 2022
6a2a16d
Updated Developers.md
PJ-Finlay Oct 16, 2022
407f06c
Merge branch 'master' into v2
PJ-Finlay Oct 16, 2022
cf9e462
v2 improvements
PJ-Finlay Oct 16, 2022
48cd8ca
Update package.py
PJ-Finlay Oct 22, 2022
7b5d0b4
Remove duplicate code
PJ-Finlay Oct 22, 2022
6f372a0
Start v2 tests
PJ-Finlay Oct 29, 2022
db03092
Improved CompositeTranslate test
PJ-Finlay Oct 29, 2022
07f6fd6
Improved format script
PJ-Finlay Oct 29, 2022
b6e9484
Merge branch 'master' into v2
PJ-Finlay Oct 29, 2022
591c6d3
Add test script
PJ-Finlay Oct 29, 2022
e2f9268
Add package.IPackage test
PJ-Finlay Oct 29, 2022
06da601
Improve IPackage test
PJ-Finlay Oct 29, 2022
3c8acca
Add test_IPackage_load_metadata_from_json_v1
PJ-Finlay Oct 29, 2022
0ead4e4
Rename IPackage.load_metadata
PJ-Finlay Oct 29, 2022
eea57b9
Rename IPackage.set_metadata
PJ-Finlay Oct 29, 2022
e5250c1
Improve argostranslate.package
PJ-Finlay Oct 29, 2022
a247746
Make regression tests
PJ-Finlay Oct 29, 2022
6349455
Deprecate argos-translate-cli
PJ-Finlay Oct 29, 2022
d049b58
Deprecate argostranslate.sbd
PJ-Finlay Oct 29, 2022
5088404
Update version information
PJ-Finlay Oct 29, 2022
ee487a6
Update setup.py
PJ-Finlay Oct 29, 2022
7eba108
Add static type checking
PJ-Finlay Oct 30, 2022
11fb43e
Remove Snapcraft script
PJ-Finlay Oct 30, 2022
fca00f8
Typing improvements
PJ-Finlay Oct 30, 2022
9896a13
Use language model for tag translation
PJ-Finlay Nov 13, 2022
bb82f3a
Improving argostranslate.tags module
PJ-Finlay Nov 13, 2022
07e3838
Fix packages path
PJ-Finlay Nov 13, 2022
292d720
Fix package path example
PJ-Finlay Nov 13, 2022
5badb48
Add docs
PJ-Finlay Nov 13, 2022
315f763
Add settings doc
PJ-Finlay Nov 13, 2022
4f3a80a
Add settings doc link
PJ-Finlay Nov 13, 2022
718e31b
Fix path in doc
PJ-Finlay Nov 13, 2022
e0ac4e3
Typo fix in docs
PJ-Finlay Nov 13, 2022
1dce154
Merge branch 'master' into v2
PJ-Finlay Nov 27, 2022
17c59f3
Test argospm list
PJ-Finlay Nov 27, 2022
08000dd
Formatting
PJ-Finlay Nov 27, 2022
80dd325
Improve argospm list test
PJ-Finlay Nov 27, 2022
b67af34
Add argospm search test
PJ-Finlay Nov 27, 2022
09e75e3
Formatting
PJ-Finlay Nov 27, 2022
032dded
Run unit tests on all branches
PJ-Finlay Nov 27, 2022
bb3fbfc
Made run-unit-test.yml
PJ-Finlay Nov 27, 2022
76d9e11
Add update_package_index to docs
PJ-Finlay Dec 5, 2022
6cef256
Merge branch 'master' into v2
PJ-Finlay Dec 31, 2022
a4c9395
Replace regression tests with integration tests
PJ-Finlay Dec 31, 2022
56dfe44
Run format script
PJ-Finlay Dec 31, 2022
36fcad6
Fix imports
PJ-Finlay Dec 31, 2022
71ac7cd
Improve argostranslate.translate tests
PJ-Finlay Dec 31, 2022
f955a84
Rename fewshot to prompt
PJ-Finlay Dec 31, 2022
4a9dd85
Revert "Rename fewshot to prompt"
PJ-Finlay Dec 31, 2022
ce5a3bc
Expand docstring
PJ-Finlay Dec 31, 2022
6a35a3b
Reword docstring
PJ-Finlay Dec 31, 2022
6edbbbf
Improved tokenization tests
PJ-Finlay Jan 2, 2023
a12b4b7
TODO update
PJ-Finlay Jan 2, 2023
0987b82
Bug fix
PJ-Finlay Jan 2, 2023
828f247
Merge branch 'master' into v2
PJ-Finlay Jan 2, 2023
f821f84
Working on type check errors
PJ-Finlay Jan 2, 2023
078d979
Move string casting
PJ-Finlay Jan 2, 2023
23608c0
Use v2 index from GitHub
PJ-Finlay Jan 18, 2023
3fcb0b9
Merge branch 'master' into v2
PJ-Finlay Feb 4, 2023
ce71555
Add Package.install v2
PJ-Finlay Feb 4, 2023
610d559
Small argostranslate.package refactoring
PJ-Finlay Feb 5, 2023
92288fd
Fix api typecheck errors
PJ-Finlay Feb 5, 2023
dec8a42
Fix type check errors
PJ-Finlay Feb 5, 2023
de90d3d
Add logging
PJ-Finlay Feb 5, 2023
628419b
Add mypy config file
PJ-Finlay Mar 4, 2023
a17149e
Fix type check errors
PJ-Finlay Mar 4, 2023
523ec6d
Rename "input_text" to "from_text"
PJ-Finlay Mar 4, 2023
5dc943d
Cleanup
PJ-Finlay Mar 4, 2023
bb41ed5
Add argostranslate.tags tests
PJ-Finlay Mar 4, 2023
a74a3b1
Consolidated dev requirements file
PJ-Finlay Mar 4, 2023
2ee9c5b
Add argostranslate.tags tests
PJ-Finlay Mar 4, 2023
e5ddfaa
Refactor translate_tag_chunk
PJ-Finlay Mar 4, 2023
5257695
Fix all mypy type errors!
PJ-Finlay Mar 4, 2023
1acdc69
Consolidate format script
PJ-Finlay Mar 4, 2023
66b9e7e
Improve import sorting
PJ-Finlay Mar 4, 2023
568786f
Fix order of hypotheses in CompositeTranslation
PJ-Finlay Mar 25, 2023
43f4ed7
Improve argostranslate.settings
PJ-Finlay Jun 2, 2023
6cf5874
Add unit tests for argostranslate.settings
PJ-Finlay Jun 2, 2023
581df70
Merge branch 'master' into v2
PJ-Finlay Aug 30, 2023
39cc641
Merge fix
PJ-Finlay Aug 30, 2023
b185172
Merge branch 'master' into v2
PJ-Finlay Oct 24, 2023
81e4bb4
Formatting
PJ-Finlay Oct 24, 2023
d21972f
Formatting
PJ-Finlay Oct 24, 2023
be036d3
Fix type error
PJ-Finlay Oct 24, 2023
789e6af
Remove v2 index
PJ-Finlay Oct 27, 2023
8a6c1f5
argostranslate.settings minor refactoring
PJ-Finlay Oct 27, 2023
acdd0d8
Add backwards compat function
PJ-Finlay Oct 27, 2023
bc010bf
Docs update
PJ-Finlay Oct 31, 2023
e050941
Backwards compatibility with 1.x models
PJ-Finlay Nov 1, 2023
341f2b8
Add package code if not exist
PJ-Finlay Nov 1, 2023
6127ce0
Fix IPackage tests
PJ-Finlay Nov 1, 2023
85b5c6d
Fix type check errors
PJ-Finlay Nov 1, 2023
fc1cbb3
Docs update
PJ-Finlay Nov 2, 2023
5a2ccac
Fix ARGOS_CHUNK_TYPE setting
PJ-Finlay Nov 2, 2023
36f282a
Improved target_prefix handling
PJ-Finlay Nov 2, 2023
c24b63a
Add target_prefix to class
PJ-Finlay Nov 2, 2023
c9c7b26
Improve target_prefix
PJ-Finlay Nov 2, 2023
5020e74
Set version number
PJ-Finlay Nov 2, 2023
893e0b0
Import argostranslate.settings
PJ-Finlay Nov 2, 2023
5c39f47
Removed dependency on packaging module
PJ-Finlay Nov 9, 2023
e9ad333
Remove putting English first
PJ-Finlay Nov 9, 2023
860e2e1
Formatting
PJ-Finlay Nov 9, 2023
485a190
Removed unused imports
PJ-Finlay Nov 9, 2023
8ba3183
Upgrade installed packages with argospm update
PJ-Finlay Nov 9, 2023
547b7bd
Add TODOs
PJ-Finlay Nov 9, 2023
3beed42
Remove unused imports
PJ-Finlay Nov 9, 2023
d791700
Merge branch 'master' into v2
PJ-Finlay May 6, 2024
a2cd1f9
Merge branch 'master' into v2
PJ-Finlay Aug 13, 2024
635f4eb
Minor refactoring
PJ-Finlay Aug 13, 2024
61e4733
Merge branch 'master' into v2
PJ-Finlay Aug 15, 2024
1601a07
Merge branch 'master' into v2
PJ-Finlay Aug 15, 2024
51a14b0
Improved settings management
PJ-Finlay Aug 15, 2024
a253add
Formatting
PJ-Finlay Aug 15, 2024
1db4060
Remove dev artifact
PJ-Finlay Aug 15, 2024
4a3732e
Fix mypy errors
PJ-Finlay Aug 15, 2024
baececa
Add TODO
PJ-Finlay Aug 15, 2024
3d2dabf
Merge branch 'master' into v2
PJ-Finlay Aug 18, 2024
e0c1187
Merge branch 'master' into v2
PJ-Finlay Aug 18, 2024
f0e3ada
Added Support for translation from English to Indic languages using I…
Parthiee Aug 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,30 +1,26 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Python package

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
on: [push]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Python 3.9
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: 3.9
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Install Argos Translate
run: |
python -m pip install .
- name: Test with pytest
run: |
pytest -v
4 changes: 3 additions & 1 deletion Developers.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Developers
Most active development happens in the `v2` branch, please make pull requests there
Contributions welcome!

Most active development happens in the `v2` branch, please make pull requests there.

## Running unit tests
```
Expand Down
28 changes: 18 additions & 10 deletions ReleaseNotes.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,34 @@
1.9:
# 2.0
- Include dependencies in packages
- Load configuration settings from file or environment variable
- Improved logging
- Refactoring for readability
- Better automated unit testing and regression testing
- Improved type checking

# 1.9:
- Add support for Byte Pair Encoding

1.8:
# 1.8:
- Delete cached package files after they've been installed
- Automatically update packages to newer version with package.Package.update

1.7:
# 1.7:
- Improved examples and documentation
- Use multiple links for redundancy and load balancing
- Add logger namespace
- CTranslate2 updates

1.6:
# 1.6:
- [Argos Translate GUI](https://github.com/argosopentech/argos-translate-gui) to separate repo
- Bug fixes
- [File translation](https://github.com/dingedi/argos-translate-files)

1.5:
# 1.5:
- Tag injection
- Upgrade to CTranslate2 2.0

1.4:
# 1.4:
- Better support for seq2seq sentence boundary detection
- py2app support
- GPU support
Expand All @@ -30,13 +38,13 @@
- Consistently use pathlib.Path in package module instead of strings
- Broke backwards compatibility with package.Package.remove

1.3:
# 1.3:
- argospm CLI tool
- CLI improvements
- Experimental sentence boundary detection using OpenNMT Seq2Seq model
- Removed requests dependency

1.2:
# 1.2:
- Download packages from GUI
- Multiple hypotheses in translations
- Deprecated load_available_packages for get_available_packages
Expand All @@ -45,7 +53,7 @@
- Broke backwards compatibility in translate.apply_packaged_translation
- Broke backwards compatibility in ITranslate.split_into_paragraphs

1.1:
# 1.1:
- Automatic downloading and installation of packages (https://github.com/uav4geo/LibreTranslate/issues/30)
- Command Line Interface
(https://github.com/argosopentech/argos-translate/issues/3)
Expand All @@ -55,5 +63,5 @@
- Changed "length_penalty" to 0.2 (https://forum.opennmt.net/t/suggested-value-for-length-penalty/4134)
- P2P model distribution support

1.0:
# 1.0:
Hello World
1 change: 1 addition & 0 deletions argostranslate/__version__
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.8.0
91 changes: 35 additions & 56 deletions argostranslate/apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,115 +2,94 @@

import json
import sys
from typing import Any, Dict
from urllib import parse, request

from argostranslate.models import ILanguageModel

# https://github.com/argosopentech/LibreTranslate-py


class LibreTranslateAPI:
"""Connect to the LibreTranslate API"""

"""Example usage:
from argostranslate.apis import LibreTranslateAPI
from libretranslatepy import LibreTranslateAPI
lt = LibreTranslateAPI("https://translate.argosopentech.com/")
print(lt.translate("LibreTranslate is awesome!", "en", "es"))
# LibreTranslate es impresionante!
print(lt.detect("Hello World"))
# [{"confidence": 0.6, "language": "en"}]

print(lt.languages())
print(lt.translate("LibreTranslate is awesome!", "en", "es"))
# [{"code":"en", "name":"English"}]
"""

DEFAULT_URL = "https://translate.argosopentech.com/"

def __init__(self, url: str = None, api_key: str = None):
def __init__(self, url: str | None = None, api_key: str | None = None):
"""Create a LibreTranslate API connection.

Args:
url: The url of the LibreTranslate endpoint.
api_key: The API key.
url (str): The url of the LibreTranslate endpoint.
api_key (str): The API key.
"""

self.url = self.DEFAULT_URL if url is None else url
self.url = LibreTranslateAPI.DEFAULT_URL if url is None else url
self.api_key = api_key

# Add trailing slash
assert len(self.url) > 0
if self.url[-1] != "/":
self.url += "/"

def translate(self, q: str, source: str = "en", target: str = "es") -> str:
def translate(self, q: str, source: str = "en", target: str = "es") -> Any:
"""Translate string

Args:
q: The text to translate
source: The source language code (ISO 639)
target: The target language code (ISO 639)

Returns: The translated text
q (str): The text to translate
source (str): The source language code (ISO 639)
target (str): The target language code (ISO 639)
Returns:
str: The translated text
"""

url = self.url + "translate"

params = {"q": q, "source": source, "target": target}

params: Dict[str, str] = {"q": q, "source": source, "target": target}
if self.api_key is not None:
params["api_key"] = self.api_key

url_params = parse.urlencode(params)

req = request.Request(url, data=url_params.encode())

response = request.urlopen(req)

response_str = response.read().decode()

return json.loads(response_str)["translatedText"]

def languages(self):
"""Retrieve list of supported languages.

Returns: A list of available languages ex. [{"code":"en", "name":"English"}]
def detect(self, q: str) -> Any:
"""Detect the language of a single text.
Args:
q (str): Text to detect
Returns:
The detected languages ex: [{"confidence": 0.6, "language": "en"}]
"""

url = self.url + "languages"

params = dict()

url = self.url + "detect"
params: Dict[str, str] = {"q": q}
if self.api_key is not None:
params["api_key"] = self.api_key

url_params = parse.urlencode(params)

req = request.Request(url, data=url_params.encode())

response = request.urlopen(req)

response_str = response.read().decode()

return json.loads(response_str)

def detect(self, q: str):
"""Detect the language of a single text.

Args:
q: Text to detect

Returns: The detected languages ex. [{"confidence": 0.6, "language": "en"}]
def languages(self) -> Any:
"""Retrieve list of supported languages.
Returns:
A list of available languages ex: [{"code":"en", "name":"English"}]
"""

url = self.url + "detect"

params = {"q": q}

url = self.url + "languages"
params: Dict[str, str] = dict()
if self.api_key is not None:
params["api_key"] = self.api_key

url_params = parse.urlencode(params)

req = request.Request(url, data=url_params.encode())

req = request.Request(url, data=url_params.encode(), method="GET")
response = request.urlopen(req)

response_str = response.read().decode()

return json.loads(response_str)


Expand Down
4 changes: 1 addition & 3 deletions argostranslate/apply_bpe.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@

class BPE(object):
def __init__(self, codes, merges=-1, separator="@@", vocab=None, glossaries=None):

codes.seek(0)
offset = 1

Expand Down Expand Up @@ -160,7 +159,6 @@ def _isolate_glossaries(self, word):


def create_parser(subparsers=None):

if subparsers:
parser = subparsers.add_parser(
"apply-bpe",
Expand Down Expand Up @@ -417,7 +415,7 @@ def isolate_glossary(word, glossary):
if __name__ == "__main__":

currentdir = os.path.dirname(
os.path.abspath(inspect.getfile(inspect.currentframe()))
os.path.abspath(inspect.getfile(inspect.currentframe())) # type: ignore
)
newdir = os.path.join(currentdir, "subword_nmt")
if os.path.isdir(newdir):
Expand Down
Loading