A package for determining the matrix language in bilingual sentences.
Project description
ml_determination
A package for determining the matrix language in bilingual sentences. This is the implementation of the algorithms presented in the paper Methods for Automatic Matrix Language Determination of Code-Switched Speech. Currently supports English/Mandarin code-switching, create a feature request if you want the system to be extended to other languages.
## Installation
The main functionality can be easily installed into your Python environment using pip:
pip install ml-determination
Usage
To predict the matrix language using the package import the library and the matrix language determination classes for text:
>>> from ml_determination.predict_matrix_language import MatrixLanguageDeterminerWordMajority
>>> ml = MatrixLanguageDeterminerWordMajority(L1='ZH', L2='EN')
>>> ml.determine_ML('然后 那些 air supply 的 然后 michael learns to rock 的 啊 certain 的 啦')
'EN'
The package includes several implementations of methods for matrix language determination:
- Word majority from Bullock et al 2018: MatrixLanguageDeterminerWordMajority
- First part of the Morpheme Order Principle from Myers-Scotton 2002, called the singleton principle in Iakovenko 2024: MatrixLanguageDeterminerP11
- Second part of the the Morpheme Order Principle as in Iakovenko 2024: MatrixLanguageDeterminerP12
- System Morpheme Principle from Myers-Scotton 2002: MatrixLanguageDeterminerP2
P1.2 matrix language determiner usage
MatrixLanguageDeterminerP12 requires trained language models for running in order to rescore code-switched sentences. To download the trained models, used in the experiments of Iakovenko 2024, clone the following repository:
cd /your/model/folder
git clone https://huggingface.co/dinoyay/ml-determination-lms
Then you can determine the matrix language using P1.2:
>>> from ml_determination.predict_matrix_language import MatrixLanguageDeterminerP12
>>> config = {
'EN': {
'data_path': '/your/model/folder/ml-determination-lms/en/',
'model_path': '/your/model/folder/ml-determination-lms/en/model.pt'},
'ZH': {
'data_path': '/your/model/folder/ml-determination-lms/zh/',
'model_path': '/your/model/folder/ml-determination-lms/zh/model.pt'
}
}
>>> ml = MatrixLanguageDeterminerP12(L1='ZH', L2='EN', config=config, alpha=1.2765)
>>> ml.determine_ML('然后 那些 air supply 的 然后 michael learns to rock 的 啊 certain 的 啦')
'EN'
Citation
If you use ml_determination in your projects, please feel free to cite the original EMNLP paper the following way:
@inproceedings{iakovenko-hain-2024-methods,
title = "Methods of Automatic Matrix Language Determination for Code-Switched Speech",
author = "Iakovenko, Olga and Hain, Thomas",
editor = "Al-Onaizan, Yaser and Bansal, Mohit and Chen, Yun-Nung",
booktitle = "Proceedings of the 2024 Conference on Empirical Methods in Natural Language Processing",
month = nov,
year = "2024",
address = "Miami, Florida, USA",
publisher = "Association for Computational Linguistics",
url = "https://aclanthology.org/2024.emnlp-main.330/",
doi = "10.18653/v1/2024.emnlp-main.330",
pages = "5791--5800"
}
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ml_determination-0.4.1.tar.gz.
File metadata
- Download URL: ml_determination-0.4.1.tar.gz
- Upload date:
- Size: 13.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.8.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
57adcd55d0c3bfe370922ed65656bafe6affcd118bae7cffa047ff532e97b102
|
|
| MD5 |
336f8e0d93f04431c8a12f49e07b00a9
|
|
| BLAKE2b-256 |
1d7994f54eaf36c217383070019217b634bf5db9650e336da90c2436d430e369
|
File details
Details for the file ml_determination-0.4.1-py3-none-any.whl.
File metadata
- Download URL: ml_determination-0.4.1-py3-none-any.whl
- Upload date:
- Size: 11.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.8.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8dcc62019f5d444aa5ee3b22aeacc3b5fbbfaa68aa26b701090d74dce6a8d8f7
|
|
| MD5 |
51339f61f14deb89d1a2a2dde8e3f609
|
|
| BLAKE2b-256 |
51ba9b6680ff9174660b8e6a65c5f6c0c5887381694563fff1110f6181fcb9fa
|