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

Upgrade eflomal #433

Merged
merged 6 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 3 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ RUN apt-get install --no-install-recommends -y \
git \
python$PYTHON_VERSION \
python3-pip \
python3-dev \
wget \
build-essential \
gdb \
Expand All @@ -59,12 +60,8 @@ RUN ln -sfn /usr/bin/python${PYTHON_VERSION} /usr/bin/python3 & \
COPY --from=builder /src/requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt && rm requirements.txt

# Install eflomal
RUN git clone https://github.com/robertostling/eflomal.git
RUN make -C eflomal/src
RUN make -C eflomal/src install
RUN rm -rf eflomal
ENV EFLOMAL_PATH=/usr/local/bin
# Set eflomal path
ENV EFLOMAL_PATH=/usr/local/lib/python3.8/dist-packages/eflomal/bin

# Install fast_align
RUN apt-get update && \
Expand Down
11 changes: 6 additions & 5 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ sacremoses = "^0.0.53"
evaluate = "^0.3.0"
python-docx = "^0.8.11"
iso639-lang = "^2.1.0"
eflomal = { version = "^0.1", optional = true }
eflomal = { version = "^2.0.0", optional = true }
accelerate = "^0.23.0"
transformers = "^4.36.2"
optimum = "^1.16.0"
Expand Down
10 changes: 2 additions & 8 deletions silnlp/alignment/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from ..common.environment import SIL_NLP_ENV
from ..common.flatcat_stemmer import FlatCatStemmer
from ..common.null_stemmer import NullStemmer
from ..common.packages_utils import is_eflomal_available
from ..common.snowball_stemmer import SnowballStemmer
from ..common.stemmer import Stemmer
from ..common.utils import merge_dict
Expand All @@ -24,10 +23,7 @@
Ibm4DotnetMachineAligner,
ParatextDotnetMachineAligner,
)

if is_eflomal_available():
from .eflomal import EflomalAligner

from .eflomal import EflomalAligner
from .fast_align import FastAlign
from .giza_aligner import HmmGizaAligner, Ibm1GizaAligner, Ibm2GizaAligner, Ibm3GizaAligner, Ibm4GizaAligner
from .machine_aligner import (
Expand Down Expand Up @@ -67,11 +63,9 @@
"clear3_fa": (ClearAligner, "Clear-3-FA"),
"clear3_hmm": (ClearAligner, "Clear-3-HMM"),
"clab_fast_align": (FastAlign, "clab-FastAlign"),
"eflomal": (EflomalAligner, "Eflomal"),
}

if is_eflomal_available():
ALIGNERS["eflomal"] = (EflomalAligner, "Eflomal")

STEMMERS: Dict[str, Type[Stemmer]] = {
"snowball": SnowballStemmer,
"wordnet": WordNetStemmer,
Expand Down
8 changes: 7 additions & 1 deletion silnlp/alignment/eflomal.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,26 @@
from tempfile import TemporaryDirectory
from typing import IO, Iterable

from eflomal import read_text, write_text
from machine.corpora import AlignedWordPair
from machine.translation import SymmetrizationHeuristic, WordAlignmentMatrix

from ..common.corpus import load_corpus
from ..common.packages_utils import is_eflomal_available
from .aligner import Aligner
from .lexicon import Lexicon
from .tools import execute_atools, execute_eflomal, is_atools_available

if is_eflomal_available():
from eflomal import read_text, write_text

LOGGER = logging.getLogger(__name__)


class EflomalAligner(Aligner):
def __init__(self, model_dir: Path) -> None:
if not is_eflomal_available():
raise RuntimeError("eflomal is not installed.")

super().__init__("eflomal", model_dir)

def train(self, src_file_path: Path, trg_file_path: Path) -> None:
Expand Down