1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
// -*- c++ -*-
#pragma once
#include <map>
#include<vector>
#include <string>
#include <iostream>
#include "moses/Util.h"
#include "ug_typedefs.h"
namespace Moses
{
namespace bitext
{
using ugdiss::id_type;
std::string query_bias_server(std::string const& url, std::string const& text);
class SamplingBias
{
public:
int loglevel;
std::ostream* log;
std::map<std::string, float> m_bias_map; //Map to store the biasmap as you get it from the server
std::map<std::string, float>& getBiasMap();
virtual float
operator[](id_type const ID) const = 0;
// returns (unnormalized bias) for the class of item ID
virtual size_t size() const = 0;
// number of classes
virtual id_type
GetClass(id_type const ID) const = 0;
// returns class of item ID
};
class
DocumentBias : public SamplingBias
{
std::vector<id_type> const& m_sid2docid;
std::vector<float> m_bias;
// std::map<int,float> m_bias;
public:
DocumentBias(std::vector<id_type> const& sid2doc,
std::map<std::string,id_type> const& docname2docid,
std::string const& server_url, std::string const& text,
std::ostream* log);
DocumentBias(std::vector<id_type> const& sid2doc,
std::map<std::string,id_type> const& docname2docid,
std::map<std::string, float> const& context_weights,
std::ostream* log);
void
init_from_json
( std::string const& json,
std::map<std::string,id_type> const& docname2docid,
std::ostream* log );
void
init
( std::map<std::string,float> const& biasmap,
std::map<std::string,id_type> const& docname2docid);
id_type
GetClass(id_type const idx) const;
float
operator[](id_type const idx) const;
size_t
size() const;
};
class
SentenceBias : public SamplingBias
{
std::vector<float> m_bias;
public:
SentenceBias(std::vector<float> const& bias);
SentenceBias(size_t const s);
id_type GetClass(id_type idx) const;
float& operator[](id_type const idx);
float operator[](id_type const idx) const;
size_t size() const;
};
}
}
|