ASTW is a small audio classification library that turns a folder of audio files and labels into a portable model artifact.
The full workflow is:
fit.save the result. You get a self-contained safetensors export with config.json, preprocessor_config.json, labels.json, metrics.json and a README.md ready to push to the Hugging Face Hub.load that folder back, locally or directly from a HF repo id, and call predict.ASTW stands for Audio Shapes The World. The library trains compact audio classifiers from scratch with a local log-mel frontend, so new models do not depend on Whisper weights or any external pretrained audio backbone.
ASTW.pip install astw
For local development:
python -m pip install -e .
To run the bundled examples:
python -m pip install -e '.[examples]'
Train from scratch on raw audios:
from astw import ASTW
audios = [
"audio/cat_01.wav",
"audio/cat_02.wav",
"audio/dog_01.wav",
"audio/dog_02.wav",
]
labels = ["cat", "cat", "dog", "dog"]
model = ASTW()
model.fit(audios, labels, epochs=8, batch_size=4)
model.save("exports/my-audio-model")
Load it back later, locally or from the Hub:
from astw import ASTW
local = ASTW.load("exports/my-audio-model")
print(local.predict("dog.wav"))
remote = ASTW.from_pretrained("your-user/your-audio-model")
print(remote.predict("clip.wav", top_k=3))
The default model is a compact encoder-only audio classifier:
Conv1d stem with temporal stride-2 downsamplingpooling="attentive_stats", with masked mean pooling kept as the defaultThe training recipe combines Muon for matrix-shaped parameters with AdamW for the rest, plus SpecAugment, cosine LR with warmup, label smoothing and macro-F1 early stopping.
You can switch the pooling policy when constructing the classifier:
ASTW(pooling="mean") # default
ASTW(pooling="attentive_stats")
save produces a folder with at least these files:
model.safetensorsconfig.jsonpreprocessor_config.jsonlabels.jsonmetrics.jsonREADME.mdThat folder can be uploaded to the Hugging Face Hub as-is and loaded with either ASTW.load(path) or ASTW.from_pretrained(repo_id).
fit and predict accept any of:
input_sample_rate= if it is not 16 kHz)(array, sample_rate) tuplearray and sample_rateastw predict path/to/audio.wav --model exports/my-audio-model
astw predict path/to/audio.wav --model your-user/your-audio-model --top-k 5
Three runnable examples are shipped with the repository:
Both follow the same 0_train.py and 1_test.py workflow and produce a confusion matrix and a metrics JSON.
A small smoke test suite lives in tests/test_smoke.py. Run it with:
python -m pip install pytest
pytest
python -m pip install build
python -m build
MIT. See LICENSE.
ASTW is a small audio classification library that turns a folder of audio files and labels into a portable model artifact.
The full workflow is:
fit.save the result. You get a self-contained safetensors export with config.json, preprocessor_config.json, labels.json, metrics.json and a README.md ready to push to the Hugging Face Hub.load that folder back, locally or directly from a HF repo id, and call predict.ASTW stands for Audio Shapes The World. The library trains compact audio classifiers from scratch with a local log-mel frontend, so new models do not depend on Whisper weights or any external pretrained audio backbone.
ASTW.pip install astw
For local development:
python -m pip install -e .
To run the bundled examples:
python -m pip install -e '.[examples]'
Train from scratch on raw audios:
from astw import ASTW
audios = [
"audio/cat_01.wav",
"audio/cat_02.wav",
"audio/dog_01.wav",
"audio/dog_02.wav",
]
labels = ["cat", "cat", "dog", "dog"]
model = ASTW()
model.fit(audios, labels, epochs=8, batch_size=4)
model.save("exports/my-audio-model")
Load it back later, locally or from the Hub:
from astw import ASTW
local = ASTW.load("exports/my-audio-model")
print(local.predict("dog.wav"))
remote = ASTW.from_pretrained("your-user/your-audio-model")
print(remote.predict("clip.wav", top_k=3))
The default model is a compact encoder-only audio classifier:
Conv1d stem with temporal stride-2 downsamplingpooling="attentive_stats", with masked mean pooling kept as the defaultThe training recipe combines Muon for matrix-shaped parameters with AdamW for the rest, plus SpecAugment, cosine LR with warmup, label smoothing and macro-F1 early stopping.
You can switch the pooling policy when constructing the classifier:
ASTW(pooling="mean") # default
ASTW(pooling="attentive_stats")
save produces a folder with at least these files:
model.safetensorsconfig.jsonpreprocessor_config.jsonlabels.jsonmetrics.jsonREADME.mdThat folder can be uploaded to the Hugging Face Hub as-is and loaded with either ASTW.load(path) or ASTW.from_pretrained(repo_id).
fit and predict accept any of:
input_sample_rate= if it is not 16 kHz)(array, sample_rate) tuplearray and sample_rateastw predict path/to/audio.wav --model exports/my-audio-model
astw predict path/to/audio.wav --model your-user/your-audio-model --top-k 5
Three runnable examples are shipped with the repository:
Both follow the same 0_train.py and 1_test.py workflow and produce a confusion matrix and a metrics JSON.
A small smoke test suite lives in tests/test_smoke.py. Run it with:
python -m pip install pytest
pytest
python -m pip install build
python -m build
MIT. See LICENSE.