Expand description
Features of a piece for machine learning: music21’s features.
Features of a piece of music, extracted for machine learning and corpus
study: music21’s features package.
A DataInstance prepares a stream once – ties stripped, every part
and voice prepared on its own – and works out each representation an
extractor asks for the first time one does: its pitches, its pitch and
interval histograms, its melodic contour. An Extractor reads those
and answers a Feature, a vector of numbers of a fixed length, each a
Value that is a whole number or a measurement as music21’s is.
jsymbolic::JSYMBOLIC holds the extractors music21 ports from Cory
McKay’s jSymbolic, and native::NATIVE those music21 adds of its own;
extractors_by_id finds them by id. A DataSet reads features of
many pieces into one table and writes it for a machine-learning tool.
use music21_rs::features::{DataInstance, jsymbolic};
use music21_rs::tinynotation::from_tiny_notation;
let line = from_tiny_notation("4/4 c4 d e f g a b c'")?;
let data = DataInstance::new(&line)?;
let range = jsymbolic::extractor("P10").expect("the range extractor");
assert_eq!(range.extract(&data)?.vector(), [12.0]);Modules§
- jsymbolic
- The features music21 ports from Cory McKay’s jSymbolic: music21’s
features.jSymbolic. Each is anExtractorinJSYMBOLIC, found by its id withextractor. - language
language-detection - Which language a text is in: music21’s
LanguageDetector, with thelanguage-detectionfeature. Which language a text is in, by the letters that follow each pair of letters: music21’stext.LanguageDetectorandtext.Trigram. - native
- The features music21 adds of its own: music21’s
features.native. Each is anExtractorinNATIVE, found by its id withextractor.
Structs§
- Data
Instance - A piece prepared for feature extraction, with each representation of it
worked out once: music21’s
DataInstanceand theStreamFormsit keeps. - DataSet
- Features of many pieces in one table: music21’s
DataSet. Each piece is a row, labelled with an id and a value of the class the set is about – its composer, say – and each extractor gives it as many columns as it has values.DataSet::processreads every feature of every piece, andDataSet::to_textwrites the table for a machine-learning tool. - Extractor
- One way of reading a feature out of a piece: music21’s
FeatureExtractor, with what its class says about the feature. - Failure
- An extractor that could not read its feature from a piece, so that the data set stands a blank feature in for it.
- Feature
- What an
Extractoranswers: its name and the vector it found. - Seconds
- Where a note sounds in time, in seconds at the tempi of the piece:
music21’s
secondsMapentry.
Enums§
- Cell
- One cell of a
DataSet’s table: a piece’s id or class, or a value. - Library
- Where an extractor comes from: music21’s jSymbolic ports or its own.
- Output
Format - A file format a
DataSetis written in: music21’sOutputFormat. - Value
- One value of a
Feature: a whole number, as a count or an index is, or a float, as a share or a measurement is. music21 keeps the two apart, a vector starting as whole noughts, and writes them apart –4and4.0– in a data set.
Functions§
- all_
features_ as_ list - Every feature of a piece, jSymbolic’s and then music21’s own, each a
blank one where it cannot be read: music21’s
allFeaturesAsList, but for its language feature. - extractor_
by_ id - The first extractor
extractors_by_idfinds for an id: music21’sextractorById. - extractors_
by_ id - The extractors with any of these ids, from these libraries, in the
libraries’ own order: music21’s
extractorsById. An id is read without regard to case, hyphens or spaces, sop-20findsP20; the idall, first, finds every extractor. Both libraries have aP22, so asking for it in both finds two. - index_
of - Where the extractor of a feature named so sits in its library, and
which library, looking through jSymbolic first unless one is given:
music21’s
getIndex, as(61, JSymbolic)forRange. Nothing for a name no extractor has. - vector_
by_ id - The values of the first extractor with an id, read from a piece:
music21’s
vectorById. Nothing for an id no extractor has.