Skip to main content

Build Translators and Translate between text & sign language videos with AI.

Project description

Sign Language Translator ⠎⠇⠞

SLT: Sign Language Translator

Build Custom Translators and Translate between Sign Language & Text with AI.

python PyPi Downloads Release Workflow Status codecov Documentation Status GitHub Repo stars


  1. Overview
    1. Solution
    2. Major Components
    3. Goals
  2. Installation 🛠️
  3. Usage
    1. Python 🐍
    2. Command Line >_
  4. Languages
  5. Models
  6. How to Build a Translator for your Sign Language
  7. Directory Tree
  8. How to Contribute
  9. Research Papers & Citation
  10. Credits and Gratitude

Overview

Sign language consists of gestures and expressions used mainly by the hearing-impaired to talk. This project is an effort to bridge the communication gap between the hearing and the hearing-impaired community using Artificial Intelligence.

This python library provides a user-friendly translation API and a framework for building sign language translators that can easily adapt to any regional sign language...
A big hurdle is the lack of datasets (global & regional) and frameworks that deep learning engineers and software developers can use to build useful products for the target community. This project aims to empower sign language translation by providing robust components, tools, datasets and models for both sign language to text and text to sign language conversion. It aims to facilitate the creation of sign language translators for any region, while building the way towards sign language standardization.
Unlike most other projects, this python library can translate full sentences and not just the alphabet.

Solution

I've have built an extensible rule-based text-to-sign translation system that can be used to generate training data for Deep Learning models for both sign to text & text to sign translation.

To create a rule-based translation system for your regional language, you can inherit the TextLanguage and SignLanguage classes and pass them as arguments to the ConcatenativeSynthesis class. To write sample texts of supported words, you can use our language models. Then, you can use that system to fine-tune our AI models. See the documentation and our datasets for more.

Major Components

  1. Sign language to Text
    1. Extract features from sign language videos
      1. See the slt.models.video_embedding sub-package and the $ slt embed command.
      2. Currently Mediapipe 3D landmarks are being used for deep learning.
    2. Transcribe and translate signs into multiple text languages to generalize the model.
    3. To train for word-for-word gloss writing task, also use a synthetic dataset made by concatenating signs for each word in a text. (See slt.models.ConcatenativeSynthesis)
    4. Fine-tune a neural network, such as one from slt.models.sign_to_text or the encoder of any multilingual seq2seq model, on your dataset.
  2. Text to Sign Language

    There are two approaches to this problem:

    1. Rule Based Concatenation

      1. Label a Sign Language Dictionary with all word tokens that can be mapped to those signs. See our mapping format here.
      2. Parse the input text and play appropriate video clips for each token.
        1. Build a text processor by inheriting slt.languages.TextLanguage (see slt.languages.text sub-package for details)
        2. Map the text grammar & words to sign language by inheriting slt.languages.SignLanguage (see slt.languages.sign sub-package for details)
        3. Use our rule-based model slt.models.ConcatenativeSynthesis for translation.
      3. It is faster but the word sense has to be disambiguated in the input. See the deep learning approach to automatically handle ambiguous words & words not in dictionary.
    2. Deep learning (seq2seq)

      1. Either generate the sequence of filenames that should be concatenated
        1. you will need a parallel corpus of normal text sentences against sign language gloss (sign sequence written word-for-word)
      2. Or synthesize the signs directly by using a pre-trained multilingual text encoder and
        1. a GAN or diffusion model or decoder to synthesize a sequence of pose vectors (shape = (time, num_landmarks * num_coordinates))
          1. Move an Avatar with those pose vectors (Easy)
          2. Use motion transfer to generate a video (Medium)
          3. Synthesize a video frame for each vector (Difficult)
        2. a video synthesis model (Very Difficult)
  3. Language Processing
    1. Sign Processing
      • 3D world landmarks extraction with Mediapipe.
      • Pose Visualization with matplotlib.
      • Pose transformations (data augmentation) with scipy.
    2. Text Processing
      • Normalize text input by substituting unknown characters/spellings with supported words.
      • Disambiguate context-dependent words to ensure accurate translation. "spring" -> ["spring(water-spring)", "spring(metal-coil)"]
      • Tokenize text (word & sentence level).
      • Classify tokens and mark them with Tags.
  4. Data Collection and Creation

    See our dataset conventions here.

    Utilities available in this package:

    1. Clip extraction from long videos using timestamps (notebook Open In Colab)
    2. Multithreaded Web scraping
    3. Language Models to generate sentences composed of supported words

    Try to capture variations in signs in a scalable and diversity accommodating way and enable advancing sign language standardization efforts.

  5. Datasets

    For our datasets, see the sign-language-datasets repo and its releases. See these docs for more on building a dataset of Sign Language videos (or motion capture gloves' output features).

    Your data should include:

    1. A word level Dictionary (Videos of individual signs & corresponding Text tokens (words & phrases))
    2. Parallel sentences
      1. Normal text language sentences against sign language videos.
      2. Normal text language sentences against the text gloss of the corresponding sign language sentence.
      3. Sign language sentences against their text gloss
      4. Sign language sentences against translations in multiple text languages
    3. Grammatical rules of the sign language
      1. Word order (e.g. SUBJECT OBJECT VERB TIME)
      2. Meaningless words (e.g. "the", "am", "are")
      3. Ambiguous words (e.g. spring(coil) & spring(water-fountain))

    Try to incorporate:

    1. Multiple camera angles
    2. Diverse performers to capture all accents of the signs
    3. Uniqueness in labeling of word tokens
    4. Variations in signs for the same concept

Goals

  1. Enable integration of sign language into existing applications.
  2. Improve education quality for the deaf and increase literacy rates.
  3. Promote communication inclusivity of the deaf.

How to install the package

pip install sign-language-translator
Editable mode (git clone):

The package ships with some optional dependencies as well (e.g. deep_translator for synonym finding and mediapipe for a pretrained pose extraction model). Install them by appending [all], [full], [mediapipe], [synonyms] to the project name in the command (e.g pip install sign-langauge-translator[full]).

git clone https://github.com/sign-language-translator/sign-language-translator.git
cd sign-language-translator
pip install -e ".[all]"
pip install -e git+https://github.com/sign-language-translator/sign-language-translator.git#egg=sign_language_translator

Usage

Head over to sign-language-translator.readthedocs.io to see the detailed usage in Python & CLI.

See the test cases or the notebooks repo to see the internal code in action.

Also see the How to build a custom sign language translator section.

Python

# Documentation: https://sign-language-translator.readthedocs.io
import sign_language_translator as slt
# print(slt.TextLanguageCodes, slt.SignLanguageCodes)

# The core model of the project (rule-based text-to-sign translator)
# which enables us to generate synthetic training datasets
model = slt.models.ConcatenativeSynthesis(
   text_language="urdu", sign_language="pk-sl", sign_format="video"
)
text = "یہ بہت اچھا ہے۔" # "This very good is."
sign = model.translate(text) # tokenize, map, download & concatenate
sign.show()
# sign.save(f"{text}.mp4")

model.text_language = "hindi"  # slt.TextLanguageCodes.HINDI  # slt.languages.text.Hindi()
sign_2 = model.translate("पाँच घंटे।") # "5 hours."

this very good is

import sign_language_translator as slt

# # Load sign-to-text model (pytorch) (COMING SOON!)
# translation_model = slt.get_model(slt.ModelCodes.Gesture)
embedding_model = slt.models.MediaPipeLandmarksModel()

sign = slt.Video("video.mp4")
embedding = embedding_model.embed(sign.iter_frames())
# text = translation_model.translate(embedding)

# print(text)
sign.show()
# slt.Landmarks(embedding, connections="mediapipe-world").show()
# custom translator (https://sign-language-translator.readthedocs.io/en/latest/#building-custom-translators)
help(slt.languages.SignLanguage)
help(slt.languages.text.Urdu)
help(slt.models.ConcatenativeSynthesis)
# help(slt.models.TransformerLanguageModel)

Command Line

$ slt

Usage: slt [OPTIONS] COMMAND [ARGS]...
   Sign Language Translator (SLT) command line interface.
   Documentation: https://sign-language-translator.readthedocs.io
Options:
  --version  Show the version and exit.
  --help     Show this message and exit.
Commands:
  assets     Assets manager to download & display Datasets & Models.
  complete   Complete a sequence using Language Models.
  embed      Embed Videos Using Selected Model.
  translate  Translate text into sign language or vice versa.

Generate training examples: write a sentence with a language model and synthesize a sign language video from it with a single command:

slt translate --model-code rule-based --text-lang urdu --sign-lang pk-sl --sign-format video \
"$(slt complete '<' --model-code urdu-mixed-ngram --join '')"

Languages

Text Languages

Available Functions:

  • Text Normalization
  • Tokenization (word, phrase & sentence)
  • Token Classification (Tagging)
  • Word Sense Disambiguation
Name Vocabulary Ambiguous tokens Signs
Urdu 2090 words+phrases 227 790
Hindi 34 words+phrases 5 16
Sign Languages

Available Functions:

  • Word & phrase mapping to signs
  • Sentence restructuring according to grammar
  • Sentence simplification (drop stopwords)
Name Vocabulary Dataset Parallel Corpus
Pakistan Sign Language 789 23 hours n gloss sentences with translations in m text languages

Models

Translation: Text to sign Language
Name Architecture Description Input Output
Concatenative Synthesis Rules + Hash Tables The Core Rule-Based translator mainly used to synthesize translation dataset.
Initialize it using TextLanguage, SignLanguage & SignFormat objects.
string slt.Sign
Sign Embedding/Feature extraction:
Name Architecture Description Input format Output format
MediaPipe Landmarks
(Pose + Hands)
CNN based pipelines. See Here: Pose, Hands Encodes videos into pose vectors (3D world or 2D image) depicting the movements of the performer. List of numpy images
(n_frames, height, width, channels)
torch.Tensor
(n_frames, n_landmarks * 5)
Data generation: Language Models

Available Trained models

Name Architecture Description Input format Output format
N-Gram Langauge Model Hash Tables Predicts the next token based on learned statistics about previous N tokens. List of tokens (token, probability)
Transformer Language Model Decoder-only Transformers (GPT) Predicts next token using query-key-value attention, linear transformations and soft probabilities. torch.Tensor
(batch, token_ids)

List of tokens
torch.Tensor
(batch, token_ids, vocab_size)

(token, probability)
Text Embedding:

Available Trained models

Name Architecture Description Input format Output format
Vector Lookup HashTable Finds token index and returns the coresponding vector. Tokenizes sentences and computes average vector of known tokens. string torch.Tensor
(n_dim,)

How to Build a Translator for Sign Language

To create your own sign language translator, you'll need these essential components:

  1. Data Collection
    1. Gather a collection of videos featuring individuals performing sign language gestures.
    2. Prepare a JSON file that maps video file names to corresponding text language words, phrases, or sentences that represent the gestures.
    3. Prepare a parallel corpus containing text language sentences and sequences of sign language video filenames.
  2. Language Processing
    1. Implement a subclass of slt.languages.TextLanguage:
      • Tokenize your text language and assign appropriate tags to the tokens for streamlined processing.
    2. Create a subclass of slt.languages.SignLanguage:
      • Map text tokens to video filenames using the provided JSON data.
      • Rearrange the sequence of video filenames to align with the grammar and structure of sign language.
  3. Rule-Based Translation
    1. Pass instances of your classes from the previous step to slt.models.ConcatenativeSynthesis class to obtain a rule-based translator object.
    2. Construct sentences in your text language and use the rule-based translator to generate sign language translations. (You can use our language models to generate such texts.)
  4. Model Fine-Tuning
    1. Utilize the sign language videos and corresponding text sentences from the previous step.
    2. Apply our training pipeline to fine-tune a chosen model for improved accuracy and translation quality.

Remember to contribute back to the community:

  • Share your data, code, and models by creating a pull request (PR), allowing others to benefit from your efforts.
  • Create your own sign language translator (e.g. as your university thesis) and contribute to a more inclusive and accessible world.

See the code at Build Custom Translator section in ReadTheDocs or in this notebook. Open In Colab

Directory Tree

sign-language-translator
├── .readthedocs.yaml
├── MANIFEST.in
├── README.md
├── poetry.lock
├── pyproject.toml
├── requirements.txt
├── docs
│   └── *
├── tests
│   └── *
│
└── sign_language_translator
    ├── cli.py `> slt` command line interface
    ├── assets (auto-downloaded)
    │   └── *
    │
    ├── config
    │   ├── assets.py download, extract and remove models & datasets
    │   ├── enums.py string short codes to identify models & classes
    │   ├── settings.py global variables in repository design-pattern
    │   ├── urls.json
    │   └── utils.py
    │
    ├── languages
    │   ├── utils.py
    │   ├── vocab.py reads word mapping datasets
    │   ├── sign
    │   │   ├── mapping_rules.py strategy design-pattern for word mapping
    │   │   ├── pakistan_sign_language.py
    │   │   └── sign_language.py Base class for sign mapping and sentence restructuring
    │   │
    │   └── text
    │       ├── english.py
    │       ├── hindi.py
    │       ├── text_language.py Base class for text normalization, tokenization & tagging
    │       └── urdu.py
    │
    ├── models
    │   ├── _utils.py
    │   ├── utils.py
    │   ├── language_models
    │   │   ├── abstract_language_model.py
    │   │   ├── beam_sampling.py
    │   │   ├── mixer.py wrap multiple models into a single object
    │   │   ├── ngram_language_model.py uses hash-tables & frequency to predict next token
    │   │   └── transformer_language_model
    │   │       ├── layers.py
    │   │       ├── model.py decoder-only transformer with controllable vocabulary
    │   │       └── train.py
    │   │
    │   ├── sign_to_text
    │   ├── text_to_sign
    │   │   ├── concatenative_synthesis.py join sign clip of each word in text using rules
    │   │   └── t2s_model.py Base class
    │   │
    │   ├── text_embedding
    │   │   ├── text_embedding_model.py Base class
    │   │   └── vector_lookup_model.py retrieves word embedding from a vector database
    │   │
    │   └── video_embedding
    │       ├── mediapipe_landmarks_model.py 3D coordinates of points on body
    │       └── video_embedding_model.py Base class
    │
    ├── text
    │   ├── metrics.py numeric score techniques
    │   ├── preprocess.py
    │   ├── subtitles.py WebVTT
    │   ├── synonyms.py
    │   ├── tagger.py classify tokens to assist in mapping
    │   ├── tokenizer.py break text into words, phrases, sentences etc
    │   └── utils.py
    │
    ├── utils
    │   ├── archive.py zip datasets
    │   ├── arrays.py common interface & operations for numpy.ndarray and torch.Tensor
    │   ├── download.py
    │   ├── parallel.py multi-threading
    │   ├── tree.py print file hierarchy
    │   └── utils.py
    │
    └── vision
        ├── _utils.py
        ├── utils.py
        ├── landmarks
        ├── sign
        │   └── sign.py Base class to wrap around sign clips
        │
        └── video
            ├── display.py jupyter notebooks inline video & pop-up in CLI
            ├── transformations.py strategy design-pattern for image augmentation
            ├── video_iterators.py adapter design-pattern for video reading
            └── video.py

How to Contribute

Datasets:

See our datasets & conventions here.

  • Implement the # TODO: in this repository.
  • Contribute by scraping, compiling, and centralizing video datasets.
  • Help with labeling word mapping datasets.
  • Establish connections with Academies for the Deaf to collaboratively develop standardized sign language grammar and integrate it into the rule-based translators.
New Code:
  • Create dedicated sign language classes catering to various regions.
  • Develop text language processing classes for diverse languages.
  • Experiment with training models using diverse hyper-parameters.
  • Don't forget to integrate string short codes of your classes and models into enums.py, and ensure to update functions like get_model() and get_.*_language().
  • Enhance the codebase with comprehensive docstrings, exemplary usage cases, and thorough test cases.
Existing Code:
  • Optimize the codebase by implementing techniques like parallel processing and batching.
  • Strengthen the project's documentation with clear docstrings, illustrative usage scenarios, and robust test coverage.
  • Contribute to the documentation for sign-language-translator ReadTheDocs to empower users with comprehensive insights. Currently it needs a template for auto-generated pages.
Product Development:
  • Engage in the development efforts across MLOps, backend, web, and mobile domains, depending on your expertise and interests.

Research Papers & Citation

Stay Tuned!

Upcoming/Roadmap

LANDMARKS_WRAPPER: v0.8
# landmarks wrapper class
# landmark augmentation

# subtitles
# trim signs before concatenation

# stabilize video batch using landmarks
LANGUAGES: v0.9
# improve Urdu code
# implement NLP class for English
# expand dictionary video data by scraping everything
MISCELLANEOUS
# bugfix: inaccurate num_frames in video file metadata
# improvement: video wrapper class uses list of sources instead of linked list of videos
# video transformations

# clean demonstration notebooks
# * host video dataset online, descriptive filenames, zip extraction
# dataset info table
# sequence diagram for creating a translator
# make deep_translator optional.
# GUI with gradio

Total Views

DEEP_TRANSLATION: v1.X
# parallel text corpus
# LanguageModel: Dropping space tokens, bidirectional prediction & train on max vocab but mask with supported only when inferring.
# sign to text with custom seq2seq transformer
# sign to text with fine-tuned whisper
# pose vector generation with fine-tuned mBERT
# custom 3DLandmark model (training data = mediapipe's output on activity recognition or any dataset)
# motion transfer
# pose2video: stable diffusion or GAN?
# speech to text
# text to speech
RESEARCH PAPERs
# datasets: clips, text, sentences, disambiguation
# rule based translation: describe entire repo
# deep sign-to-text: pipeline + experiments
# deep text-to-sign: pipeline + experiments
PRODUCT DEVELOPMENT
# ML inference server
# Django backend server
# React Frontend
# React Native mobile app

Credits and Gratitude

This project started in October 2021 as a BS Computer Science final year project with 3 students and 1 supervisor. After 9 months at university, it became a hobby project for Mudassar who has continued it till at least 2024-03-18.

Immense gratitude towards: (click to expand)
  • Mudassar Iqbal for coding the project so far.
  • Rabbia Arshad for help in initial R&D and web development.
  • Waqas Bin Abbas for assistance in initial video data collection process.
  • Kamran Malik for setting the initial project scope, idea of motion transfer and connecting us with Hamza Foundation.
  • Hamza Foundation (especially Ms Benish, Ms Rashda & Mr Zeeshan) for agreeing to collaborate and providing their sign dictionary, hearing-impaired performers for data creation, and creating the text2gloss dataset.
  • UrduHack for their work on Urdu character normalization.
  • Telha Bilal for help in designing the architecture of some modules.

Bonus

Count total number of lines of code (Package: 10,731 + Tests: 1,822):

git ls-files | grep '\.py' | xargs wc -l

Just for fun

Q: What was the deaf student's favorite course?
A: Communication skills
Star History Star History Chart

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sign_language_translator-0.7.3.tar.gz (1.0 MB view hashes)

Uploaded Source

Built Distribution

sign_language_translator-0.7.3-py3-none-any.whl (1.0 MB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page