nameprediction
nameprediction is a Python package for predicting gender, country, and region from personal names using a byte-level transformer.
The repository contains both:
- the reusable inference package under
src/nameprediction - the original training and local inference scripts used to produce checkpoints
Install
For local development:
pip install -e .
For users after publication:
pip install nameprediction
Quick Start
1. Download a model from Hugging Face
from nameprediction import download_model
model_path = download_model()
The same flow is available from the CLI:
nameprediction-download-model
By default this downloads from romor/nameprediction and fetches name_gender_country_model_v14.pth.
You can override the source explicitly if needed:
model_path = download_model(repo_id="romor/nameprediction")
Direct model URLs also work:
model_path = download_model("https://example.com/name_gender_country_model_v14.pth")
2. Load the predictor
from nameprediction import NamePredictor
predictor = NamePredictor.from_pretrained()
If you already downloaded the model and want to point at a specific local path, use:
predictor = NamePredictor.from_pretrained(
model_path=model_path,
)
Predict Single Names
result = predictor.predict_name("Ada Lovelace")
print(result)
print(result.to_dict())
predict_name returns a NamePrediction dataclass with these fields:
namepredicted_genderf_probpredicted_countrypredicted_country_confidencepredicted_regionpredicted_region_confidence
Predict Lists Of Names
results = predictor.predict_names([
"Ada Lovelace",
"Alan Turing",
"Grace Hopper",
])
You can also use the convenience function:
from nameprediction import predict_names
results = predict_names(["Ada Lovelace", "Alan Turing"])
Predict DataFrames
import pandas as pd
from nameprediction import predict_dataframe
df = pd.DataFrame({"name": ["Ada Lovelace", "Alan Turing"]})
predicted = predict_dataframe(
df,
name_col="name",
column_suffix="_v15",
)
This appends:
predicted_gender_v15f_prob_v15predicted_country_v15predicted_country_confidence_v15predicted_region_v15predicted_region_confidence_v15
Package Notes
- The package derives model architecture settings such as
embed_dim,num_heads,num_layers, andmax_lenfrom the checkpoint when available. - Label encoders are bundled with the package and validated against the checkpoint class counts at load time.
- The default published model source is
romor/namepredictionwith filenamename_gender_country_model_v14.pth. - You can override the default model source with
repo_id=...,filename=..., or the environment variablesNAMEPREDICTION_HF_REPO_ID,NAMEPREDICTION_MODEL_FILENAME, andNAMEPREDICTION_MODEL_REVISION.
Repository Layout
src/nameprediction: package code intended for PyPI userstrain.py: original training scriptinference.py: legacy local inference helper scriptconfig.yaml: local training and inference configuration
Publishing
Maintainer instructions for PyPI and Hugging Face are in PUBLISHING.md.
Release files for nameprediction 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| nameprediction-0.1.1.tar.gz | 10.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| nameprediction-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 21.7 kB
Release files / nameprediction-0.1.1.tar.gz
| Download URL | nameprediction-0.1.1.tar.gz |
|---|---|
| Size | 10.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
817677311fc1750e90c57d965ba61181623f9ae490eb0b9e40c26cf70f747dab
|
|
BLAKE2b-256 checksum How to use checksums |
816813f415a4debf3e16666cdc7b948f4e5b277812921b24558353beab3078c4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.2
|
Release files / nameprediction-0.1.1-py3-none-any.whl
| Download URL | nameprediction-0.1.1-py3-none-any.whl |
|---|---|
| Size | 11.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5df2650daeaf7ae1ea2fed05a04f4c67b87bcbe77fe6d711782c69270711e434
|
|
BLAKE2b-256 checksum How to use checksums |
2e03666f793c989d658f68d091da5cb07ab769b883865c5cf5313b5d54586005
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.2
|