GithubHelp home page GithubHelp logo

richermans / plda Goto Github PK

View Code? Open in Web Editor NEW
99.0 10.0 24.0 153 KB

An LDA/PLDA estimator using KALDI in python for speaker verification tasks

CMake 23.01% C++ 33.03% Python 43.96%
kaldi speaker-verification plda

plda's Introduction

PLDA

An LDA/PLDA estimator using KALDI in python for speaker verification tasks

Installation

Make sure that you have KALDI compiled and installed. Further make sure that KALDI was compiled using the option --shared, during ./configure (e.g. ./configure --shared). Moreover the included ATLAS within KALDI is sufficient that PLDA works. If any compilation errors happen it's most likely that not all of the ATLAS libraries was installed successfully.

Moreover to find KALDI correctly, please run:

export KALDI_ROOT=/your/path/to/root

if your ATLAS is installed in a different directory please set the variable ATLAS_DIR e.g.

export ATLAS_DIR=/your/atlas/dir

Then just run:

git clone https://github.com/RicherMans/PLDA
cd PLDA
mkdir build && cd build && cmake ../ && make

Per default cmake is installing the python package into your /usr/lib directory. If this is not wised, pass the option -DUSER=ON to cmake to install the packages only for the current user

Voila, the python library is copied to your local users installation path.

Usage

Generally we use this script to do LDA/PLDA scoring. First we need to fit a model using LDA/PLDA.

For LDA:

from liblda import LDA
lda = LDA()
n_samples=500, featdim = 200
X=np.random.rand(n_samples,featdim)
Y=np.random.randint(0,2,n_samples).astype('uint') # for binary labels

lda.fit(X,Y)

For PLDA:

from liblda import PLDA
plda = PLDA()

n_samples=500, featdim = 200

X=np.random.rand(n_samples,featdim)
Y=np.random.randint(0,2,n_samples).astype('uint') # for binary labels

plda.fit(X,Y)

Note that fitting the model in the LDA case is done using enrolment data, while for PLDA we use background data ( which can be any data).

PLDA fit does also accept one extra argument:

#Transform the features first to a given target dimension. Default is keeping the dimension
targetdim=10
plda.fit(X,Y,targetdim)

LDA can then after fitting be used to directly score any incoming utterance using predict_log_proba(SAMPLE)

pred = np.random.rand(featdim)[np.newaxis,...]
scores = lda.predict_log_proba(pred)

the predict_log_proba method returns a list where each element in the last represents the likelihood for the indexed class.

For PLDA one can also do standard normalization methods such as z-norm (other norms are not implemented yet). For this case, simply transform your enrolment vectors (labeled as ENROL_X,ENROL_Y) into the PLDA space and then normalize them using any other data ( but do not use the background data from .fit() ). Generally it is recommended to have an held out set to do this estimation. The normalization procedure will then estimate the mean and variance of the scores of the enrolment models against the held out set (Otherdata).

ENROL_X=np.random.rand(n_samples,featdim)
ENROL_Y=np.arange(n_samples,dtype='uint')
#Smoothing factor does increase the performance. Its a value between 0 and 1. #Does affect the covariance matrix. Optional!
smoothing=0.5

#Transform the features first to a given target dimension. Default is keeping the dimension
targetdim=10

transformed_vectors = plda.transform(ENROL_X,ENROL_Y,targetdim,smoothing)

Otherdata = np.random.rand(m_samples,featdim)
plda.norm(Otherdata,transformed_vectors)

Note that if targetdim is given, all future plda.transform() calls also need targetdim as a valid parameter

And finally one can score any model against a utterance by:

Models_X=np.random.rand(n_samples,featdim)
Models_Y=np.arange(n_samples,dtype='uint')
transformed_vectors = plda.transform(Models_X,Models_Y)

testutt_x=np.random.rand(n_samples,featdim)
testutt_y=np.arange(n_samples,dtype='uint')

transformedtest_vectors=plda.transform(testutt_x,testutt_y)

for model,modelvec in transformed_vectors.iteritems():
  for testutt,testvec in transformedtest_vectors.iteritems():
    #model is an integer which represents the current class, need for normalization
    #modelvec is a tuple consisting of (samplesize,datavector)
    #testvec is a tuple consisting of (samplesize,datavector)
    score=plda.score(model,modelvec,testvec)

Note that the modelid is necessary only if one wants to normalize using z-norm.

plda's People

Contributors

richermans avatar skoppula avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

plda's Issues

can not clone submodule

HELLO RicherMans
when i clone your resp,i use 'git clone [email protected]:RicherMans/PLDA.git --recursive'
but it tell me these

Cloning into 'PLDA'...
remote: Enumerating objects: 723, done.
remote: Total 723 (delta 0), reused 0 (delta 0), pack-reused 723
Receiving objects: 100% (723/723), 151.66 KiB | 52.00 KiB/s, done.
Resolving deltas: 100% (447/447), done.
Checking connectivity... done.
fatal: no submodule mapping found in .gitmodules for path 'scoring/htkpython'

is the submodule exist at this time?or i do something wrong?

THANK YOU

error during compilation

hi,

i'm trying to follow the installation procedure but when i try "make" it is throwing some errors like

/home/rohit/speech/development/speaker_verification/PLDA/src/kaldi-utils.hpp:101:26: error: 'PyArrayObject' has no member named 'dimensions'

/home/rohit/speech/development/speaker_verification/PLDA/src/kaldi-utils.hpp:101:26: error: 'PyArrayObject' has no member named 'desc'

etc, there are some other issues like this, i don't think these are because of ATLAS, is there anyway to solve it and my numpy is of updated version

Does it support the latest Kaldi?

Hi, RicherMans,

I installed the latest Kaldi. When I make files, it reports
/home/xliu/PLDA/src/kaldi-utils.hpp: In function ‘kaldi::Matrix kaldi::readFeatureFromPyString(PyObject*)’:
/home/xliu/PLDA/src/kaldi-utils.hpp:44:41: error: ‘PyString_Check’ was not declared in this scope
PyString_Check(pyfeaturefilename);
^
/home/xliu/PLDA/src/kaldi-utils.hpp:45:74: error: ‘PyString_AsString’ was not declared in this scope
const char* featurefilename = PyString_AsString(pyfeaturefilename);
^
/home/xliu/PLDA/src/pldamodule.cpp: In function ‘PyObject* kaldi::Mplda_transform(kaldi::MPlda*, PyObject*, PyObject*)’:
/home/xliu/PLDA/src/pldamodule.cpp:173:57: error: ‘PyInt_FromSize_t’ was not declared in this scope

and other errors like these. I am wondering which Kaldi version does your python wrapper support?

Thank you very much.

Using kaldi plda model

Hi Dear
How can I use Kaldi plda model?
suppose I have a plda model and two lists of i(x)-vectors in python, how can compute the distance between two vectors?

e.g.
I download Kaldi x-vector moel https://kaldi-asr.org/models/7/0007_voxceleb_v1_1a.tar.gz
and extract x-vectors of two voices and have two lists of numbers (or NumPy arrays) in python e.g.
enrol = [1,1,1,1]
eval = [2,2,2,2]
how can compute plda between two lists like above with the plda model?

thanks

Some error in installing

when i run the following command,

cmake ../ && make in "./build" dir.

it shows the following error:

-- Kaldi root: /home/kaldi/
Kaldi root is not an svn checkout. Kaldi revision unknown.
-- Kaldi libraries: /home/kaldi/src/decoder/kaldi-decoder.a;/home/kaldi/src/feat/kaldi-feat.a;/home/kaldi/src/gmm/kaldi-gmm.a;/home/kaldi/src/hmm/kaldi-hmm.a;/home/kaldi/src/lat/kaldi-lat.a;/home/kaldi/src/matrix/kaldi-matrix.a;/home/kaldi/src/transform/kaldi-transform.a;/home/kaldi/src/tree/kaldi-tree.a;/home/kaldi/src/util/kaldi-util.a;/home/kaldi/src/base/kaldi-base.a;/home/kaldi/src/ivector/kaldi-ivector.a
-- OpenFst include: /home/kaldi/tools/openfst/include
-- OpenFst library: /home/kaldi/tools/openfst/lib/libfst.a
User mode is off, if installation is unsucessful please pass -DUSER=ON
-- Configuring done
-- Generating done
-- Build files have been written to: /home/qinxy/PLDA/build
[ 33%] Built target chtk
[ 50%] Built target utils
[ 66%] Building CXX object CMakeFiles/plda.dir/src/pldamodule.cpp.o
In file included from /usr/local/lib/python3.5/dist-packages/numpy/core/include/numpy/ndarraytypes.h:1822:0,
from /usr/local/lib/python3.5/dist-packages/numpy/core/include/numpy/ndarrayobject.h:12,
from /usr/local/lib/python3.5/dist-packages/numpy/core/include/numpy/arrayobject.h:4,
from /home/qinxy/PLDA/src/pldamodule.cpp:10:
/usr/local/lib/python3.5/dist-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:17:2: warning: #warning "Using deprecated NumPy API, disable it with " "#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]
#warning "Using deprecated NumPy API, disable it with "
^
In file included from /home/qinxy/PLDA/src/pldamodule.cpp:15:0:
/home/qinxy/PLDA/chtk/chtk.h: In constructor ‘chtk::htkarray::htkarray(size_t, size_t, size_t, size_t, size_t)’:
/home/qinxy/PLDA/chtk/chtk.h:49:10: warning: ‘chtk::htkarray::parmkind’ will be initialized after [-Wreorder]
size_t parmkind;
^
/home/qinxy/PLDA/chtk/chtk.h:45:10: warning: ‘size_t chtk::htkarray::frm_ext’ [-Wreorder]
size_t frm_ext;
^
/home/qinxy/PLDA/chtk/chtk.h:21:3: warning: when initialized here [-Wreorder]
htkarray(size_t _nsamples, size_t _sample_period, size_t _samplesize, size_t _parmkind, size_t _frm_ext):
^
/home/qinxy/PLDA/chtk/chtk.h: In constructor ‘chtk::htkarray::htkarray()’:
/home/qinxy/PLDA/chtk/chtk.h:49:10: warning: ‘chtk::htkarray::parmkind’ will be initialized after [-Wreorder]
size_t parmkind;
^
/home/qinxy/PLDA/chtk/chtk.h:45:10: warning: ‘size_t chtk::htkarray::frm_ext’ [-Wreorder]
size_t frm_ext;
^
/home/qinxy/PLDA/chtk/chtk.h:28:3: warning: when initialized here [-Wreorder]
htkarray():nsamples(0), sample_period(0), samplesize(0), parmkind(0), frm_ext(0) {}
^
In file included from /home/qinxy/PLDA/src/pldamodule.cpp:17:0:
/home/qinxy/PLDA/src/kaldi-utils.hpp: In function ‘kaldi::Matrix kaldi::readFeatureFromPyString(PyObject*)’:
/home/qinxy/PLDA/src/kaldi-utils.hpp:44:41: error: ‘PyString_Check’ was not declared in this scope
PyString_Check(pyfeaturefilename);
^
/home/qinxy/PLDA/src/kaldi-utils.hpp:45:74: error: ‘PyString_AsString’ was not declared in this scope
const char* featurefilename = PyString_AsString(pyfeaturefilename);
^
/home/qinxy/PLDA/src/pldamodule.cpp: In function ‘PyObject* kaldi::Mplda_transform(kaldi::MPlda*, PyObject*, PyObject*)’:
/home/qinxy/PLDA/src/pldamodule.cpp:173:57: error: ‘PyInt_FromSize_t’ was not declared in this scope
PyObject* spkid = PyInt_FromSize_t(it->first);
^
/home/qinxy/PLDA/src/pldamodule.cpp: In function ‘PyObject* kaldi::MPlda_norm(kaldi::MPlda*, PyObject*, PyObject*)’:
/home/qinxy/PLDA/src/pldamodule.cpp:229:37: error: ‘PyInt_Check’ was not declared in this scope
if(! PyInt_Check(key)) return NULL;
^
/home/qinxy/PLDA/src/pldamodule.cpp:232:42: error: ‘PyInt_AsLong’ was not declared in this scope
long k = PyInt_AsLong(key);
^
/home/qinxy/PLDA/src/pldamodule.cpp: In function ‘PyObject* kaldi::MPlda_score(kaldi::MPlda*, PyObject*, PyObject*)’:
/home/qinxy/PLDA/src/pldamodule.cpp:263:73: error: ‘PyInt_AsLong’ was not declared in this scope
long samplesize = PyInt_AsLong(PyTuple_GetItem(py_enrolemodel,0));
^
/home/qinxy/PLDA/src/pldamodule.cpp: In function ‘void kaldi::MPLDA_dealloc(kaldi::MPlda*)’:
/home/qinxy/PLDA/src/pldamodule.cpp:314:15: error: ‘struct kaldi::MPlda’ has no member named ‘ob_type’
self->ob_type->tp_free((PyObject*)self);
^
/home/qinxy/PLDA/src/pldamodule.cpp: At global scope:
/home/qinxy/PLDA/src/pldamodule.cpp:359:5: error: invalid conversion from ‘const char*’ to ‘Py_ssize_t {aka long int}’ [-fpermissive]
};
^
/home/qinxy/PLDA/src/pldamodule.cpp:359:5: error: invalid conversion from ‘destructor {aka void ()(_object)}’ to ‘printfunc {aka int ()(_object, _IO_FILE*, int)}’ [-fpermissive]
/home/qinxy/PLDA/src/pldamodule.cpp:359:5: error: invalid conversion from ‘long unsigned int’ to ‘const char*’ [-fpermissive]
/home/qinxy/PLDA/src/pldamodule.cpp:359:5: error: cannot convert ‘const char*’ to ‘traverseproc {aka int ()(_object, int ()(_object, void*), void*)}’ in initialization
/home/qinxy/PLDA/src/pldamodule.cpp:359:5: error: cannot convert ‘PyMethodDef*’ to ‘PyMemberDef*’ in initialization
/home/qinxy/PLDA/src/pldamodule.cpp:359:5: error: invalid conversion from ‘PyObject* ()(PyTypeObject, PyObject*, PyObject*) {aka _object* ()(_typeobject, _object*, _object*)}’ to ‘freefunc {aka void ()(void)}’ [-fpermissive]
/home/qinxy/PLDA/src/pldamodule.cpp: In function ‘PyObject* kaldi::initlibplda()’:
/home/qinxy/PLDA/src/pldamodule.cpp:374:17: error: return-statement with no value, in function returning ‘PyObject* {aka _object*}’ [-fpermissive]
return;
^
/home/qinxy/PLDA/src/pldamodule.cpp:376:76: error: ‘Py_InitModule3’ was not declared in this scope
"Example module that creates an extension type.");
^
/home/qinxy/PLDA/src/pldamodule.cpp:378:17: error: return-statement with no value, in function returning ‘PyObject* {aka _object*}’ [-fpermissive]
return;
^
/home/qinxy/PLDA/src/pldamodule.cpp: In function ‘PyObject* kaldi::MPlda_norm(kaldi::MPlda*, PyObject*, PyObject*)’:
/home/qinxy/PLDA/src/pldamodule.cpp:256:5: warning: control reaches end of non-void function [-Wreturn-type]
}
^
/home/qinxy/PLDA/src/pldamodule.cpp: In function ‘PyObject* kaldi::initlibplda()’:
/home/qinxy/PLDA/src/pldamodule.cpp:384:9: warning: control reaches end of non-void function [-Wreturn-type]
}
^
CMakeFiles/plda.dir/build.make:62: recipe for target 'CMakeFiles/plda.dir/src/pldamodule.cpp.o' failed
make[2]: *** [CMakeFiles/plda.dir/src/pldamodule.cpp.o] Error 1
CMakeFiles/Makefile2:142: recipe for target 'CMakeFiles/plda.dir/all' failed
make[1]: *** [CMakeFiles/plda.dir/all] Error 2
Makefile:127: recipe for target 'all' failed
make: *** [all] Error 2

could you help me solve the problem?thank you

Could not find Atlas

I install KALDI (using ./configure --shared) and export KALDI. There is a question about export ATLAS_DIR, I find that kaldi only install ATLAS HEADER, so the ATLAS_DIR directory is what?
I tried to let ATLAS_DIR = KALDI_root or KALDI/tools/ATLAS_headers, but both of them failed.
{PMPB0A4S1P)3Y7U I2LNGR

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.