Skip to main content

RaceBERT -- A transformer based model to predict race and ethnicty from names

Installation

pip install racebert

Using a virtual environment is highly recommended! You may need to install pytorch as instructed here: https://pytorch.org/get-started/locally/

Paper

Todo

Usage

raceBERT predicts race (U.S census race) and ethnicity from names.

from racebert import RaceBERT

model = RaceBERT()

# To predict race
model.predict_race("Barack Obama")
>>> {"label": "nh_black", "score": 0.5196923613548279}

The race categories are:

Race Label
Non-hispanic White nh_white
Hispanic hispanic
Non-hispanic Black nh_black
Asian & Pacific Islander api
American Indian & Alaskan Native aian
# Predict ethnicity
model.predict_ethnicty("Arjun Gupta")
>>> {"label": "Asian,IndianSubContinent", "score": 0.9612812399864197}

The ethnicity categories are:

Ethnicity
GreaterEuropean,British
GreaterEuropean,WestEuropean,French
GreaterEuropean,WestEuropean,Italian
GreaterEuropean,WestEuropean,Hispanic
GreaterEuropean,Jewish
GreaterEuropean,EastEuropean
Asian,IndianSubContinent
Asian,GreaterEastAsian,Japanese
GreaterAfrican,Muslim
Asian,GreaterEastAsian,EastAsian
GreaterEuropean,WestEuropean,Nordic
GreaterEuropean,WestEuropean,Germanic
GreaterAfrican,Africans

GPU

If you have a GPU, you can speed up the computation by specifying the CUDA device when you instantiate the model.

from racebert import RaceBERT

model = RaceBERT(device=0)

# predict race in batch
model.predict_race(["Barack Obama", "George Bush"])
>>>
[
        {"label": "nh_black", "score": 0.5196923613548279},
        {"label": "nh_white", "score": 0.8365859389305115}
]
# predict ethnicity in batch
model.predict_ethnicity(["Barack Obama", "George Bush"])

HuggingFace

Alternatively, you can work with the transformers models hosted on the huggingface hub directly.

Please refer to the transformers documentation.

Metadata

Release files for racebert 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for racebert 1.1.0
File Size Uploaded Provenance
racebert-1.1.0.tar.gz 3.1 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for racebert 1.1.0
File Interpreter ABI Platform
racebert-1.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 6.2 kB

Release files / racebert-1.1.0.tar.gz

Download URL racebert-1.1.0.tar.gz
Size 3.1 kB
Tags Source
SHA-256 checksum
How to use checksums
2078e1b813368f2a23c48df448bf9aa49bcfd772092c5405791bd829637ffbf5
BLAKE2b-256 checksum
How to use checksums
8fc4f15c3e3fe9929323a628e1c08d82e278bf533e9e4df173e9891d5df93718
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.5.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.0

Release files / racebert-1.1.0-py3-none-any.whl

Download URL racebert-1.1.0-py3-none-any.whl
Size 3.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cb2c78a0ef9bb282f1980c29950edea054d91ae1175ebbd4996ff23e1a29e8e6
BLAKE2b-256 checksum
How to use checksums
62b3ce1665a9c5c1cae6592d79c3b83d782982999a830776e1ebf2439e0de180
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.5.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.0

Security for racebert 1.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page