MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
TokenizedDataPairsParameter.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
6using MyCaffe.basecode;
8
9namespace MyCaffe.param.gpt
10{
14 [Serializable]
15 [TypeConverter(typeof(ExpandableObjectConverter))]
17 {
18 string m_strTarget = "";
19 string m_strSourceVocabFile = "";
20 string m_strTargetVocabFile = "";
21 int m_nMaxLoad = 0;
22 string m_strVocabDataUrl = "";
23 string m_strVocabDataDstFile = "";
24
27 {
28 vocabulary_type = VOCABULARY_TYPE.SENTENCEPIECE;
29 }
30
35 [Description("Specifies the data target (decoder input) based on the INPUT_TYPE used. Each dataset has both a training and testing data source and target consisting of matching lines.")]
36 public string target
37 {
38 get { return m_strTarget; }
39 set { m_strTarget = value; }
40 }
41
45 [Description("Specifies the URL to the vocabulary data file used with the SENTENCEPIECE vocabulary type. This pre-created vocabulary file is also created using the Python SentencePieceProcess.")]
46 public string vocab_data_url
47 {
48 get { return m_strVocabDataUrl; }
49 set { m_strVocabDataUrl = value; }
50 }
51
55 public string vocab_data_dst_file
56 {
57 get { return m_strVocabDataDstFile; }
58 set { m_strVocabDataDstFile = value; }
59 }
60
64 [Description("Specifies the source vocabulary file used with the SENTENCEPIECE vocabulary type. The vocabulary file is created using the Python SentencePieceProcess.")]
65 public string source_vocab_file
66 {
67 get { return m_strSourceVocabFile; }
68 set { m_strSourceVocabFile = value; }
69 }
70
74 [Description("Specifies the target vocabulary file used with the SENTENCEPIECE vocabulary type. The vocabulary file is created using the Python SentencePieceProcess.")]
75 public string target_vocab_file
76 {
77 get { return m_strTargetVocabFile; }
78 set { m_strTargetVocabFile = value; }
79 }
80
84 [Description("Specifies the maximum items to load - primarily used for testing.")]
85 public int max_load
86 {
87 get { return m_nMaxLoad; }
88 set { m_nMaxLoad = value; }
89 }
90
92 public override object Load(System.IO.BinaryReader br, bool bNewInstance = true)
93 {
94 RawProto proto = RawProto.Parse(br.ReadString());
96
97 if (!bNewInstance)
98 Copy(p);
99
100 return p;
101 }
102
104 public override void Copy(LayerParameterBase src)
105 {
106 base.Copy(src);
107
109 {
111 m_strTarget = p.target;
112 m_strSourceVocabFile = p.source_vocab_file;
113 m_strTargetVocabFile = p.target_vocab_file;
114 m_nMaxLoad = p.max_load;
115 m_strVocabDataUrl = p.vocab_data_url;
116 m_strVocabDataDstFile = p.vocab_data_dst_file;
117 }
118 }
119
121 public override LayerParameterBase Clone()
122 {
124 p.Copy(this);
125 return p;
126 }
127
133 public override RawProto ToProto(string strName)
134 {
135 RawProto rpBase = base.ToProto("data");
136 RawProtoCollection rgChildren = new RawProtoCollection();
137
138 if (rpBase != null)
139 rgChildren.Add(rpBase.Children);
140 rgChildren.Add("target", "\"" + target + "\"");
141 rgChildren.Add("target_vocab_file", "\"" + target_vocab_file + "\"");
142 rgChildren.Add("source_vocab_file", "\"" + source_vocab_file + "\"");
143 rgChildren.Add("vocab_data_url", "\"" + vocab_data_url + "\"");
144 rgChildren.Add("vocab_data_dst_file", "\"" + vocab_data_dst_file + "\"");
145
146 if (max_load > 0)
147 rgChildren.Add("max_load", max_load.ToString());
148
149 return new RawProto(strName, "", rgChildren);
150 }
151
158 {
159 string strVal;
161
163
164 if ((strVal = rp.FindValue("target")) != null)
165 p.target = strVal;
166
167 if ((strVal = rp.FindValue("target_vocab_file")) != null)
168 p.target_vocab_file = strVal;
169
170 if ((strVal = rp.FindValue("source_vocab_file")) != null)
171 p.source_vocab_file = strVal;
172
173 if ((strVal = rp.FindValue("max_load")) != null)
174 p.max_load = int.Parse(strVal);
175
176 if ((strVal = rp.FindValue("vocab_data_url")) != null)
177 p.vocab_data_url = strVal;
178
179 if ((strVal = rp.FindValue("vocab_data_dst_file")) != null)
180 p.vocab_data_dst_file = strVal;
181
182 return p;
183 }
184 }
185}
The RawProtoCollection class is a list of RawProto objects.
void Add(RawProto p)
Adds a RawProto to the collection.
The RawProto class is used to parse and output Google prototxt file data.
Definition: RawProto.cs:17
RawProtoCollection Children
Returns a collection of this nodes child nodes.
Definition: RawProto.cs:96
static RawProto Parse(string str)
Parses a prototxt and places it in a new RawProto.
Definition: RawProto.cs:306
string FindValue(string strName)
Searches for a falue of a node within this nodes children.
Definition: RawProto.cs:105
The LayerParameterBase is the base class for all other layer specific parameters.
Specifies the parameters for the TokenizedDataPairsLayer.
int max_load
Specifies the maximum items to load - primarily used for testing.
string vocab_data_url
Specifies the URL to the vocabulary data file used with the SENTENCEPIECE vocabulary type....
static new TokenizedDataPairsParameter FromProto(RawProto rp)
Parses the parameter from a RawProto.
override LayerParameterBase Clone()
Creates a new copy of this instance of the parameter.
override RawProto ToProto(string strName)
Convert the parameter into a RawProto.
string vocab_data_dst_file
Specifies the destination file where the vocabulary data file data is downloaded. This pre-created vo...
string target_vocab_file
Specifies the target vocabulary file used with the SENTENCEPIECE vocabulary type. The vocabulary file...
string source_vocab_file
Specifies the source vocabulary file used with the SENTENCEPIECE vocabulary type. The vocabulary file...
string target
Specifies the data source based on the INPUT_TYPE used. Each dataset has both a training and testing ...
TokenizedDataPairsParameter()
Constructor for the parameter.
override void Copy(LayerParameterBase src)
Copy on parameter to another.
override object Load(System.IO.BinaryReader br, bool bNewInstance=true)
Load the parameter from a binary reader.
Specifies the parameters for the TokenizedDataLayer.
static TokenizedDataParameter FromProto(RawProto rp)
Parses the parameter from a RawProto.
VOCABULARY_TYPE vocabulary_type
Specifies the vocabulary type to use.
TokenizedDataParameter()
Constructor for the parameter.
VOCABULARY_TYPE
Defines the vocabulary type to use.
The MyCaffe.basecode contains all generic types used throughout MyCaffe.
Definition: Annotation.cs:12
The MyCaffe.param namespace contains parameters used to create models.
The MyCaffe namespace contains the main body of MyCaffe code that closesly tracks the C++ Caffe open-...
Definition: Annotation.cs:12