Skip to main content

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:

  1. Word majority from Bullock et al 2018: MatrixLanguageDeterminerWordMajority
  2. First part of the Morpheme Order Principle from Myers-Scotton 2002, called the singleton principle in Iakovenko 2024: MatrixLanguageDeterminerP11
  3. Second part of the the Morpheme Order Principle as in Iakovenko 2024: MatrixLanguageDeterminerP12
  4. 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 的 啦')
'ZH'

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"
}

Acknowledgements

This code was created with the support of Engineering and Physical Sciences Research Council.

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

ml_determination-1.0.1.tar.gz (12.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ml_determination-1.0.1-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

Details for the file ml_determination-1.0.1.tar.gz.

File metadata

  • Download URL: ml_determination-1.0.1.tar.gz
  • Upload date:
  • Size: 12.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.12

File hashes

Hashes for ml_determination-1.0.1.tar.gz
Algorithm Hash digest
SHA256 57ee051a1d3813858ca3a806df8d43ff9cbd25a9d2fbde5b07c7821e0f9bb9be
MD5 c146e8e4b08c224a706ec859ebc50150
BLAKE2b-256 0b9e5fb8f7b6eb230d2fc88e38a07f4a3354b709c38999e8d9eda5e5092cc51a

See more details on using hashes here.

File details

Details for the file ml_determination-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for ml_determination-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d1377e65db32f88e5faa5125e464e6c664571678e02f0a4895eb8e68dee9e7af
MD5 1abb8e768ca40583852babc6354cc9dc
BLAKE2b-256 c3abacb6301afcf043bb2632e2f49a3cb1acf0ed8e58f9677cc07cf78b1d5555

See more details on using hashes here.

Supported by

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