- Overview
- Installation
🛠️
- Usage
- Languages
- Models
- How to Build a Translator for your Sign Language
- Directory Tree
- How to Contribute
- Research Papers & Citation
- Credits and Gratitude
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.
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.
-
Sign language to Text
- Extract features from sign language videos
- See the
slt.models.video_embedding
sub-package and the$ slt embed
command. - Currently Mediapipe 3D landmarks are being used for deep learning.
- See the
- Transcribe and translate signs into multiple text languages to generalize the model.
- 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
) - 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.
- Extract features from sign language videos
-
Text to Sign Language
There are two approaches to this problem:
-
Rule Based Concatenation
- Label a Sign Language Dictionary with all word tokens that can be mapped to those signs. See our mapping format here.
- Parse the input text and play appropriate video clips for each token.
- Build a text processor by inheriting
slt.languages.TextLanguage
(seeslt.languages.text
sub-package for details) - Map the text grammar & words to sign language by inheriting
slt.languages.SignLanguage
(seeslt.languages.sign
sub-package for details) - Use our rule-based model
slt.models.ConcatenativeSynthesis
for translation.
- Build a text processor by inheriting
- 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.
-
Deep learning (seq2seq)
- Either generate the sequence of filenames that should be concatenated
- you will need a parallel corpus of normal text sentences against sign language gloss (sign sequence written word-for-word)
- Or synthesize the signs directly by using a pre-trained multilingual text encoder and
- a GAN or diffusion model or decoder to synthesize a sequence of pose vectors (
shape = (time, num_landmarks * num_coordinates)
)- Move an Avatar with those pose vectors (Easy)
- Use motion transfer to generate a video (Medium)
- Synthesize a video frame for each vector (Difficult)
- a video synthesis model (Very Difficult)
- a GAN or diffusion model or decoder to synthesize a sequence of pose vectors (
- Either generate the sequence of filenames that should be concatenated
-
-
Language Processing
- Sign Processing
- 3D world landmarks extraction with Mediapipe.
- Pose Visualization with matplotlib.
- Pose transformations (data augmentation) with scipy.
- 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.
- Sign Processing
-
Data Collection and Creation
See our dataset conventions here.
Utilities available in this package:
- Clip extraction from long videos using timestamps (notebook )
- Multithreaded Web scraping
- 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.
-
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:
- A word level Dictionary (Videos of individual signs & corresponding Text tokens (words & phrases))
- Parallel sentences
- Normal text language sentences against sign language videos.
- Normal text language sentences against the text gloss of the corresponding sign language sentence.
- Sign language sentences against their text gloss
- Sign language sentences against translations in multiple text languages
- Grammatical rules of the sign language
- Word order (e.g. SUBJECT OBJECT VERB TIME)
- Meaningless words (e.g. "the", "am", "are")
- Ambiguous words (e.g. spring(coil) & spring(water-fountain))
Try to incorporate:
- Multiple camera angles
- Diverse performers to capture all accents of the signs
- Uniqueness in labeling of word tokens
- Variations in signs for the same concept
- Enable integration of sign language into existing applications.
- Improve education quality for the deaf and increase literacy rates.
- Promote communication inclusivity of the deaf.
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
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.
# 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."
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)
$ 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 '')"
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 |
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
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:
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,) |
To create your own sign language translator, you'll need these essential components:
-
Data Collection
- Gather a collection of videos featuring individuals performing sign language gestures.
- Prepare a JSON file that maps video file names to corresponding text language words, phrases, or sentences that represent the gestures.
- Prepare a parallel corpus containing text language sentences and sequences of sign language video filenames.
-
Language Processing
- Implement a subclass of
slt.languages.TextLanguage
:- Tokenize your text language and assign appropriate tags to the tokens for streamlined processing.
- 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.
- Implement a subclass of
-
Rule-Based Translation
- Pass instances of your classes from the previous step to
slt.models.ConcatenativeSynthesis
class to obtain a rule-based translator object. - 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.)
- Pass instances of your classes from the previous step to
-
Model Fine-Tuning
- Utilize the sign language videos and corresponding text sentences from the previous step.
- 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.
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
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 intoenums.py
, and ensure to update functions likeget_model()
andget_.*_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:
Stay Tuned!
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
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
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.
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