Skip to main content

SUGAR metrics in python

Project description

sugarpy

sugarpy

A library, API and web app for using NLP to perform language sample analysis using the SUGAR framework. This is primarily meant as a tool for Speech Language Pathologists (SLPs) to expedite the often time-consuming process of computing SUGAR metrics by hand. The main mode of use for SLPs is the web application here. Behind the web application is an API hosted in Google Cloud. Documentation for that API is here.

The sugarpy python library is the core driver of the tool. It uses classical NLP (spacy) to perform rule-based and token based analysis on the input language samples. In the future, LLM support will be added to augment the tool and improve accuracy.

Install

To install the python library, use pip:

pip install sugar-python

You can also clone this repo and install from source using poetry:

pip install poetry
poetry install

Next you will need to install the default model:

python -m spacy download en_core_web_lg

Use

The main operation in sugarpy is get_metrics:

from sugarpy import get_metrics

language_samples = [
  "My last name is Y and my middle name is Z",
  "And you can take this bag off and wear it",
  "But it’s a little small",
  "Yea mine didn’t come with one that matches",
  "It didn’t come with this; it came with these markers"
]

metrics = get_metrics(language_samples)

The result is an object with the four SUGAR metrics as attributes: mlu (mean length utterance), cps (clauses per sentence), wps (words per sentence), and tnw (total number of words).

One can also check whether the resulting metrics are within established averages. The mean and standard deviation for each score depends on the subject's age, and they are found in sugarpy/norms.py. To retrieve them, use get_norms:

from sugarpy import get_norms

age_y = 4 #Age in years
age_m = 11 #Age in months
norms = get_norms(age_y,age_m, "mlu") # Returns {'min_age': 108, 'max_age': 131, 'mean_score': 9.61, 'sd': 1.52}

The min_age and max_age are measured in months, and are the age range for which the mean_score and sd (standard deviation) apply. In the above example, children between the ages of 108 months and 131 months have a mean mlu score of 9.61, with a standard deviation of 1.52.

All of this data is taken directly from the SUGAR language website.

Configuration

The library is configured to use the spacy model en_core_web_lg by default. This is a CPU-performant token classification model. You can substitute a different spacy model, such as a transformer-based one like en_core_web_trf, by passing model=<your_model_name> to the get_metrics function:

from sugarpy import get_metrics

...

metrics = get_metrics(language_samples, model="en_core_web_trf")

You will need to ensure that any model you pass has already been installed on your machine.

License

This project is licensed under the MIT license. Please see LICENSE for details.

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

sugar_python-0.4.2.tar.gz (13.5 kB view details)

Uploaded Source

Built Distribution

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

sugar_python-0.4.2-py3-none-any.whl (15.6 kB view details)

Uploaded Python 3

File details

Details for the file sugar_python-0.4.2.tar.gz.

File metadata

  • Download URL: sugar_python-0.4.2.tar.gz
  • Upload date:
  • Size: 13.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for sugar_python-0.4.2.tar.gz
Algorithm Hash digest
SHA256 6836c28776d88a85e1effc4148e354f5384d9f15e5e3b7fc39fa70921884cfb9
MD5 5b38381aa4c433b19b10f209f1234783
BLAKE2b-256 471c9416fe5dc016801aa858d9316321cd63fa2cdfa37c0c9230235a5986eb4c

See more details on using hashes here.

Provenance

The following attestation bundles were made for sugar_python-0.4.2.tar.gz:

Publisher: publish.yaml on geodavic/sugarpy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sugar_python-0.4.2-py3-none-any.whl.

File metadata

  • Download URL: sugar_python-0.4.2-py3-none-any.whl
  • Upload date:
  • Size: 15.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for sugar_python-0.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7d5c254e397d88200e96b5b94239f80bc73eaab50c554f99a3459320d3fa74bc
MD5 76be74bf60b9415f2f605349c82e3a52
BLAKE2b-256 aa434e33a7c9c58d9365f736fdbd62801bb078992ac24afc2ffecb51d9196ef6

See more details on using hashes here.

Provenance

The following attestation bundles were made for sugar_python-0.4.2-py3-none-any.whl:

Publisher: publish.yaml on geodavic/sugarpy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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