コード例 #1
0
ファイル: pregroupparser.cpp プロジェクト: wetneb/stocpreg
//! What is the probability of this type assignment ?
float SPGParser::proba(Assignment a)
{
    float prob = 1.0;
    for(Assignment::iterator it = a.begin();
            it != a.end(); it++)
        prob *= proba(*it);
    return prob;
}
コード例 #2
0
ファイル: pregroupparser.cpp プロジェクト: wetneb/stocpreg
//! Create the union with another set
Assignment Assignment::createUnion(const Assignment &rhs) const
{
    Assignment a(*this);

    for(Assignment::iterator it = rhs.begin();
            it != rhs.end(); it++)
        a.insert(*it);

    return a;
}
コード例 #3
0
ファイル: learning.cpp プロジェクト: wetneb/stocpreg
Lexicon<ComplexType> LexiconLearner::run(vector<list<string> > &sentences, int nbIterations, float dirichletPrior, bool verbose)
{
    SimpleType targetType("s", 0);

    for(int i = 0; i < nbIterations; i++)
    {
        // /*
        if(i > 0)
            verbose = false;
        // */

        Lexicon<ComplexType> counts;

        cout << "ITERATION "<<i+1<<endl;
        float logLikelihood = 0;

        // Parsing and counting
        for(unsigned int s = 0; s < sentences.size(); s++)
        {
            FrameString fs(mLex, sentences[s], targetType);
            if(verbose)
                cout << fs.toString() << endl;

            SPGParser ps(fs);
            float totalProba = ps.run();
            if(verbose)
                cout << "Probability : "<<totalProba<<endl;
            set<Assignment> as = ps.getAssignments();
            for(set<Assignment>::iterator it = as.begin();
                    it != as.end(); it++)
            {
                Assignment a = *it;
                float proba = ps.proba(a);
                list<string>::iterator word = sentences[s].begin();
                if(verbose)
                    cout << "Assignment (proba "<<proba<<"): "<<endl;
                for(Assignment::iterator typ = a.begin();
                        typ != a.end(); typ++)
                {
                    if(word != sentences[s].end())
                    {
                        if(verbose)
                            cout << *word << " -> "<< fs.getType(*typ).toString() << " (type id "<<*typ<<")"<<endl;
                        counts[*word].addCount(fs.getType(*typ), proba);
                        word++;
                    }
                }
            }
            if(verbose)
                cout << endl;
            else cout << "." << flush;

            logLikelihood += log(totalProba);
        }
        if(!verbose)
            cout << endl;

        // Normalizing
        counts.normalize(dirichletPrior);
        // Pruning
        counts.pruneZeros();

        cout << counts.toString();

        mLex = counts;
        
        cout << "Perplexity (before last step): "<<-logLikelihood<<endl;
    }

    return mLex;
}