Package: elpis
Elpis Core LibraryThe Core Elpis Library, providing a quick api to:hugs: transformersfor automatic-speech-recognition.You can use the library to:Perform standalone inference using a pretrained HFT model.Fine tune a pretrained ASR model on your own dataset.Generate text and Elan files from inference results for further analysis.DocumentationDocumentation for the library can be be foundhere.DependenciesWhile we try to be as machine-independant as possible, there are some dependencies
you should be aware of when using this library:Processing datasets (elpis.datasets.processing) requireslibrosa, which
depends on havinglibsndfileinstalled on your computer. If you're using
elpis within a docker container, you may have to manually installlibsndfile.Transcription (elpis.transcription.transcribe) requiresffmpegif your
audio you're attempting to transcribe needs to be resampled before it can
be used. The default sample rate we assume is 16khz.The preprocessing flow (elpis.datasets.preprocessing) is free of external
dependencies.InstallationYou can install the elpis library with:pip3 install elpisUsageBelow are some typical examples of use casesStandalone InferencefrompathlibimportPathfromelpis.transcriber.resultsimportbuild_textfromelpis.transcriber.transcribeimportbuild_pipeline,transcribe# Perform inferenceasr=build_pipeline(pretrained_location="facebook/wav2vec2-base-960h")audio=Path("<to_some_audio_file.wav>")annotations=transcribe(audio,asr)# Timed, per word annotation dataresult=build_text(annotations)# Combine annotations to extract all textprint(result)# Build output filestext_file=output_dir/"test.txt"withopen(text_file,"w")asoutput_file:output_file.write(result)Fine-tuning a Pretrained Model on Local DatasetfrompathlibimportPathfromtypingimportListfromelpis.datasetsimportDatasetfromelpis.datasets.datasetimportCleaningOptionsfromelpis.datasets.preprocessingimportprocess_batchfromelpis.modelsimportElanOptions,ElanTierSelectorfromelpis.trainer.jobimportTrainingJob,TrainingOptionsfromelpis.trainer.trainerimporttrainfromelpis.transcriber.resultsimportbuild_elan,build_textfromelpis.transcriber.transcribeimportbuild_pipeline,transcribefiles:List[Path]=[...]# A list of paths to the files to include.dataset=Dataset(name="dataset",files=files,cleaning_options=CleaningOptions(),# Default cleaning options# Elan data extraction info- required if dataset includes .eaf files.elan_options=ElanOptions(selection_mechanism=ElanTierSelector.NAME,selection_value="Phrase"),)# Setuptmp_path=Path('...')dataset_dir=tmp_path/"dataset"model_dir=tmp_path/"model"output_dir=tmp_path/"output"# Make all directoriesfordirectoryindataset_dir,model_dir,output_dir:directory.mkdir(exist_ok=True,parents=True)# Preprocessingbatches=dataset.to_batches()forbatchinbatches:process_batch(batch,dataset_dir)# Train the modeljob=TrainingJob(model_name="some_model",dataset_name="some_dataset",options=TrainingOptions(epochs=2,learning_rate=0.001),base_model="facebook/wav2vec2-base-960h")train(job=job,output_dir=model_dir,dataset_dir=dataset_dir,)# Perform inference with pipelineasr=build_pipeline(pretrained_location=str(model_dir.absolute()),)audio=Path("<to_some_audio_file.wav>")annotations=transcribe(audio,asr)# Build output filestext_file=output_dir/"test.txt"withopen(text_file,"w")asoutput_file:output_file.write(build_text(annotations))elan_file=output_dir/"test.eaf"eaf=build_elan(annotations)eaf.to_file(str(elan_file))print('voila ;)')