MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
TokenizedDataLayer.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using MyCaffe.basecode;
6using MyCaffe.common;
7using MyCaffe.param;
8using MyCaffe.fillers;
9using System.IO;
10using MyCaffe.db.image;
11using MyCaffe.param.gpt;
12using System.Net;
13
14namespace MyCaffe.layers.gpt
15{
20 public class TokenizedDataLayer<T> : Layer<T>
21 {
22 CancelEvent m_evtCancel;
23 InputData m_data;
24 Blob<T> m_blobX = null;
25 Blob<T> m_blobY = null;
26 Random m_random = new Random();
27 Layer<T> m_softmax = null;
28 bool m_bEnableEos = false;
29 bool m_bEnableBos = false;
30
53 : base(cuda, log, p)
54 {
55 m_evtCancel = evtCancel;
56 m_type = LayerParameter.LayerType.TOKENIZED_DATA;
57
58 m_blobX = new Blob<T>(m_cuda, m_log);
59 }
60
64 protected override void dispose()
65 {
66 dispose(ref m_blobY);
67 dispose(ref m_blobX);
68 dispose(ref m_softmax);
69
70 base.dispose();
71 }
72
76 public override int MaxBottomBlobs
77 {
78 get { return (m_phase == Phase.RUN) ? 1 : 0; }
79 }
80
84 public override int MinBottomBlobs
85 {
86 get { return 0; }
87 }
88
92 public override int ExactNumTopBlobs
93 {
94 get { return (m_phase == Phase.RUN) ? 2 : 3; }
95 }
96
102 public override void LayerSetUp(BlobCollection<T> colBottom, BlobCollection<T> colTop)
103 {
104 int nBlockSize = (int)m_param.tokenized_data_param.block_size;
105
107 {
108 case TokenizedDataParameter.INPUT_TYPE.TEXT_FILE:
110 break;
111
112 default:
113 throw new Exception("Unknown input type '" + m_param.tokenized_data_param.input_type.ToString() + "'");
114 }
115
116 Reshape(colBottom, colTop);
117
118 Blob<T> blobPos = colTop[1];
119 List<int> rgShape = Utility.Clone<int>(colTop[1].shape());
120 rgShape[1] = nBlockSize;
121 blobPos.Reshape(rgShape);
122
123 // Set the position data = 0, 1, 2, 3, ... block_size-1
124 float[] rgPos = new float[nBlockSize];
125 for (int i = 0; i < nBlockSize; i++)
126 {
127 rgPos[i] = i;
128 }
129
130 blobPos.mutable_cpu_data = convert(rgPos);
131 }
132
138 public override void Reshape(BlobCollection<T> colBottom, BlobCollection<T> colTop)
139 {
140 if (m_phase == Phase.RUN)
141 {
142 int nBatchSize = colBottom[0].num;
143 int nBlockSize = (int)m_param.tokenized_data_param.block_size;
144 int nTokenSize = (int)m_data.TokenSize;
145
146 Blob<T> blobData = colTop[0];
147 Blob<T> blobPos = colTop[1];
148 Blob<T> blobTarget = null;
149
150 if (colTop.Count > 2)
151 blobTarget = colTop[2];
152
153 int nCount = 3;
154 if (nTokenSize == 1)
155 nCount = 2;
156 int[] rgShape = new int[nCount];
157
158 blobData.SetParameter("vocab_size", m_data.VocabularySize);
159
160 int nC = colBottom[0].channels;
161 if (nC > nBlockSize)
162 throw new Exception("The bottom input channel count cannot exceed the block_size=" + nBlockSize.ToString());
163
164 // reshape for single characters (each character is an index into the vocab vector)
165 rgShape[0] = nBatchSize;
166 rgShape[1] = nC;
167 if (rgShape.Length > 2)
168 rgShape[2] = nTokenSize;
169
170 blobData.Reshape(rgShape);
171 if (blobTarget != null)
172 blobTarget.Reshape(rgShape);
173
174 if (blobPos.count() < nBlockSize)
175 {
176 rgShape[0] = 1;
177 if (rgShape.Length > 2)
178 rgShape[2] = 1;
179
180 blobPos.Reshape(rgShape);
181 }
182
183 rgShape[0] = nBatchSize;
184 rgShape[1] = nC;
185 blobPos.Reshape(rgShape);
186
187 m_blobX.Reshape(1, nBlockSize, 1, 1);
188 }
189 else
190 {
191 m_log.CHECK_EQ(colBottom.Count, 0, "Data Layer takes no input blobs.");
192 m_log.CHECK_EQ(colTop.Count, 3, "The TokenizedDataLayer requires 3 top blobs.");
193
194 int nBatchSize = (int)m_param.tokenized_data_param.batch_size;
195 int nBlockSize = (int)m_param.tokenized_data_param.block_size;
196 int nTokenSize = (int)m_data.TokenSize;
197
198 Blob<T> blobData = colTop[0];
199 Blob<T> blobPos = colTop[1];
200 Blob<T> blobTarget = colTop[2];
201
202 int nCount = 3;
203 if (nTokenSize == 1)
204 nCount = 2;
205 int[] rgShape = new int[nCount];
206
207 blobData.SetParameter("vocab_size", m_data.VocabularySize);
208 // reshape for single characters (each character is an index into the vocab vector)
209 rgShape[0] = nBatchSize;
210 rgShape[1] = nBlockSize;
211 if (rgShape.Length > 2)
212 rgShape[2] = nTokenSize;
213
214 blobData.Reshape(rgShape);
215 blobTarget.Reshape(rgShape);
216
217 rgShape[0] = 1;
218 if (rgShape.Length > 2)
219 rgShape[2] = 1;
220 blobPos.Reshape(rgShape);
221 }
222 }
223
236 protected override void forward(BlobCollection<T> colBottom, BlobCollection<T> colTop)
237 {
238 if (m_phase == Phase.RUN)
239 {
240 m_log.CHECK_EQ(colBottom.Count, 1, "There must be one input blob when running.");
241 colTop[0].CopyFrom(colBottom[0]);
242 // Top[1] should already have pos data in it.
243 // There is no Top[2] target data when running.
244 }
245 else
246 {
247 int[] rgnIdx;
248 Tuple<float[], float[]> data = m_data.GetData((int)m_param.tokenized_data_param.batch_size, (int)m_param.tokenized_data_param.block_size, null, out rgnIdx);
249
250 colTop[0].mutable_cpu_data = convert(data.Item1);
251 if (colTop.Count > 2)
252 colTop[2].mutable_cpu_data = convert(data.Item2);
253 }
254 }
255
257 protected override void backward(BlobCollection<T> colTop, List<bool> rgbPropagateDown, BlobCollection<T> colBottom)
258 {
259 }
260
264 public override bool SupportsPreProcessing
265 {
266 get { return true; }
267 }
268
272 public override bool SupportsPostProcessingLogits
273 {
274 get { return true; }
275 }
276
284 public List<int> Tokenize(string str, bool bAddBos, bool bAddEos)
285 {
286 m_bEnableBos = bAddBos;
287 m_bEnableEos = bAddEos;
288 return m_data.Tokenize(str, bAddBos, bAddEos);
289 }
290
300 public string Detokenize(float[] rg, int nStartIdx, int nCount, bool bIgnoreBos = true, bool bIgnoreEos = true)
301 {
302 return m_data.Detokenize(rg, nStartIdx, nCount, bIgnoreBos, bIgnoreEos);
303 }
304
312 public override BlobCollection<T> PreProcessInput(PropertySet customInput, out int nSeqLen, BlobCollection<T> colBottom = null)
313 {
315
316 Blob<T> blobIdx = new Blob<T>(m_cuda, m_log, false);
317
318 string strInput = customInput.GetProperty("InputData");
319 if (string.IsNullOrEmpty(strInput))
320 throw new Exception("Could not find 'InputData' property!");
321
322 int[] rgShape = new int[2];
323 rgShape[0] = 1;
324 rgShape[1] = strInput.Length;
325
326 blobIdx.Reshape(rgShape);
327
328 List<int> rgTokens = m_data.Tokenize(strInput, false, false);
329 float[] rgInput = new float[rgTokens.Count];
330
331 for (int i = 0; i < strInput.Length; i++)
332 {
333 rgInput[i] = rgTokens[i];
334 }
335
336 blobIdx.mutable_cpu_data = convert(rgInput);
337
338 return new BlobCollection<T>() { blobIdx };
339 }
340
348 public override bool PreProcessInput(string str, int? nTokIdx, BlobCollection<T> colBottom = null)
349 {
350 if (nTokIdx.HasValue && m_bEnableEos && nTokIdx.Value == (int)SPECIAL_TOKENS.EOS)
351 return false;
352
353 List<float> rgTok = convertF(colBottom[0].mutable_cpu_data).ToList();
354
355 rgTok.Add(nTokIdx.Value);
356 if (rgTok.Count > m_param.tokenized_data_param.block_size)
357 rgTok.RemoveAt(0);
358
359 List<int> rgShape = Utility.Clone<int>(colBottom[0].shape());
360 rgShape[1] = rgTok.Count;
361 colBottom[0].Reshape(rgShape);
362
363 colBottom[0].mutable_cpu_data = convert(rgTok.ToArray());
364
365 return true;
366 }
367
380 public override List<Tuple<string, int, double>> PostProcessLogitsOutput(int nCurIdx, Blob<T> blobLogits, Layer<T> softmax, int nAxis, int nK = 1)
381 {
382 float[] rgData = convertF(blobLogits.mutable_cpu_data);
383 int nVocabCount = blobLogits.count(nAxis);
384 float[] rgLogits = new float[nVocabCount];
385 int nIdxStart = blobLogits.count() - nVocabCount;
386 Dictionary<int, float> rgTopK = new Dictionary<int, float>();
387
388 for (int i = nIdxStart; i < blobLogits.count(); i++)
389 {
390 float fVal = rgData[i];
391 rgTopK.Add(i - nIdxStart, fVal);
392
393 if (rgTopK.Count > nK)
394 {
395 float fMin = float.MaxValue;
396 int nMinIdx = -1;
397
398 foreach (KeyValuePair<int, float> kv in rgTopK)
399 {
400 if (kv.Value < fMin)
401 {
402 fMin = kv.Value;
403 nMinIdx = kv.Key;
404 }
405 }
406
407 rgTopK.Remove(nMinIdx);
408 }
409 }
410
411 for (int i = 0; i < rgLogits.Count(); i++)
412 {
413 if (rgTopK.ContainsKey(i))
414 rgLogits[i] = rgTopK[i];
415 else
416 rgLogits[i] = -float.MaxValue;
417 }
418
419 if (m_blobX == null)
420 m_blobX = new Blob<T>(m_cuda, m_log, false);
421 if (m_blobY == null)
422 m_blobY = new Blob<T>(m_cuda, m_log, false);
423
424 m_blobX.Reshape(1, 1, nVocabCount, 1);
425 m_blobX.mutable_cpu_data = convert(rgLogits);
426
427 BlobCollection<T> colBottom = new BlobCollection<T>() { m_blobX };
428 BlobCollection<T> colTop = new BlobCollection<T>() { m_blobY };
429 if (softmax == null)
430 {
431 if (m_softmax == null)
432 {
433 LayerParameter softmax_param = new LayerParameter(LayerParameter.LayerType.SOFTMAX);
434 softmax_param.softmax_param.axis = nAxis;
435 m_softmax = Layer<T>.Create(m_cuda, m_log, softmax_param, null);
436 m_softmax.Setup(colBottom, colTop);
437 }
438
439 softmax = m_softmax;
440 }
441 softmax.Forward(colBottom, colTop);
442
443 float[] rgProb = convertF(m_blobY.mutable_cpu_data);
444 int nCharIdx = (m_param.tokenized_data_param.sample_method == TokenizedDataParameter.SAMPLE_METHOD.PROBABILITY) ? sample(rgProb) : argmax(rgProb);
445
446 string str = "";
447 str += m_data.Detokenize(nCharIdx, true, true);
448
449 return new List<Tuple<string, int, double>>() { new Tuple<string, int, double>(str, nCharIdx, 0) };
450 }
451
452 private int argmax(float[] rgData)
453 {
454 int nMaxIdx = 0;
455 float fMax = rgData[0];
456
457 for (int i = 1; i < rgData.Length; i++)
458 {
459 if (rgData[i] > fMax)
460 {
461 fMax = rgData[i];
462 nMaxIdx = i;
463 }
464 }
465
466 return nMaxIdx;
467 }
468
469 private int sample(float[] rgData)
470 {
471 float fTotal = 0;
472 float fRand = (float)m_random.NextDouble();
473
474 for (int i = 0; i < rgData.Length; i++)
475 {
476 fTotal += rgData[i];
477
478 if (fTotal >= fRand)
479 return i;
480 }
481
482 return rgData.Length - 1;
483 }
484 }
485
501 {
502 string m_strData;
503 IVocabulary m_vocab;
504 string m_strDebugIndexFile;
505 List<int> m_rgDebugIdx = null;
506 int m_nDebugIdx = 0;
507 float[] m_rgData = null;
508 float[] m_rgTgt = null;
509 Phase m_phase;
510
511
520 public TextInputData(string strSrc, TokenizedDataParameter.VOCABULARY_TYPE vocabType = TokenizedDataParameter.VOCABULARY_TYPE.CHARACTER, int? nRandomSeed = null, string strDebugIndexFile = null, Phase phase = Phase.NONE) : base(nRandomSeed)
521 {
522 string strProgData = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);
523 strSrc = Utility.ReplaceMacro(strSrc, "$ProgramData$", strProgData);
524
525 m_phase = phase;
526 m_strData = File.ReadAllText(strSrc);
527
528 if (File.Exists(strDebugIndexFile))
529 {
530 m_strDebugIndexFile = Utility.ReplaceMacro(strDebugIndexFile, "$ProgramData$", strProgData);
531 m_rgDebugIdx = new List<int>();
532 string[] rgLines = File.ReadAllLines(strDebugIndexFile);
533 foreach (string strLine in rgLines)
534 {
535 if (strLine.StartsWith("idx = "))
536 {
537 string strIdx = strLine.Substring(6).Trim(' ', '\t', '\n', '\r');
538 m_rgDebugIdx.Add(int.Parse(strIdx));
539 }
540 }
541 }
542
543 if (vocabType == TokenizedDataParameter.VOCABULARY_TYPE.WORD)
544 m_vocab = new VocabularyWord(m_random, false, false);
545 else
546 m_vocab = new VocabularyCharacter(m_random, false, false, false);
547
548 m_vocab.BuildFromString(m_strData);
549 }
550
554 public override List<string> RawData
555 {
556 get
557 {
558 return new List<string>() { m_strData };
559 }
560 }
561
565 public override uint TokenSize
566 {
567 get { return 1; }
568 }
569
573 public override uint VocabularySize
574 {
575 get { return (uint)m_vocab.Count; }
576 }
577
585 public override bool GetDataAvailabilityAt(int nIdx, bool bIncludeSrc, bool bIncludeTrg)
586 {
587 return true;
588 }
589
599 public override Tuple<float[], float[]> GetData(int nBatchSize, int nBlockSize, InputData trgData, out int[] rgnIdx)
600 {
601 int nSize = nBatchSize * nBlockSize;
602
603 rgnIdx = new int[nBatchSize];
604
605 if (m_rgData == null || m_rgData.Length != nSize)
606 m_rgData = new float[nSize];
607
608 if (m_rgTgt == null || m_rgTgt.Length != nSize)
609 m_rgTgt = new float[nSize];
610
611 for (int i = 0; i < nBatchSize; i++)
612 {
613 int nMax = m_strData.Count() - (nBlockSize + 1);
614 int nDataIdx = m_random.Next(nMax);
615 int nDstIdx = i * nBlockSize;
616
617 rgnIdx[i] = nDataIdx;
618
619 if (m_rgDebugIdx != null)
620 {
621 nDataIdx = m_rgDebugIdx[m_nDebugIdx];
622 m_nDebugIdx++;
623
624 if (m_nDebugIdx >= m_rgDebugIdx.Count)
625 m_nDebugIdx = 0;
626 }
627
628 List<int> rgTokens = new List<int>();
629 List<int> rgLastTokens;
630 int nIdx = 0;
631
632 while (rgTokens.Count < nBlockSize + 1)
633 {
634 rgLastTokens = m_vocab.Tokenize(m_strData[nDataIdx + nIdx].ToString());
635 if (rgLastTokens.Count > 0)
636 rgTokens.AddRange(rgLastTokens);
637
638 nIdx++;
639 }
640
641 Array.Copy(rgTokens.ToArray(), 0, m_rgData, nDstIdx, nBlockSize);
642 rgTokens.RemoveAt(0);
643 Array.Copy(rgTokens.ToArray(), 0, m_rgTgt, nDstIdx, nBlockSize);
644 }
645
646 return new Tuple<float[], float[]>(m_rgData, m_rgTgt);
647 }
648
656 public override Tuple<float[], float[]> GetDataAt(int nBatchSize, int nBlockSize, int[] rgnIdx)
657 {
658 throw new NotImplementedException();
659 }
660
668 public override List<int> Tokenize(string str, bool bAddBos, bool bAddEos)
669 {
670 return m_vocab.Tokenize(str, bAddBos, bAddEos).ToList();
671 }
672
680 public override string Detokenize(int nTokIdx, bool bIgnoreBos, bool bIgnoreEos)
681 {
682 return m_vocab.Detokenize(nTokIdx, bIgnoreBos, bIgnoreEos);
683 }
684
694 public override string Detokenize(float[] rgfTokIdx, int nStartIdx, int nCount, bool bIgnoreBos, bool bIgnoreEos)
695 {
696 string str = "";
697 for (int i = nStartIdx; i < nStartIdx + nCount; i++)
698 {
699 string strItem = m_vocab.Detokenize((int)rgfTokIdx[i], bIgnoreBos, bIgnoreEos);
700 if (string.IsNullOrEmpty(strItem))
701 break;
702
703 str += strItem;
704 }
705
706 return str;
707 }
708
712 public override char BOS
713 {
714 get { return m_vocab.BOS; }
715 }
716
720 public override char EOS
721 {
722 get { return m_vocab.EOS; }
723 }
724 }
725}
The CancelEvent provides an extension to the manual cancel event that allows for overriding the manua...
Definition: CancelEvent.cs:17
The Log class provides general output in text form.
Definition: Log.cs:13
void CHECK_EQ(double df1, double df2, string str)
Test whether one number is equal to another.
Definition: Log.cs:239
Specifies a key-value pair of properties.
Definition: PropertySet.cs:16
string GetProperty(string strName, bool bThrowExceptions=true)
Returns a property as a string value.
Definition: PropertySet.cs:146
The Utility class provides general utility funtions.
Definition: Utility.cs:35
static string ReplaceMacro(string strRaw, string strMacroName, string strReplacement)
The ConvertMacro method is used to replace a set of macros in a given string.
Definition: Utility.cs:947
static int Count(List< int > rgShape, int nStartIdx=0, int nEndIdx=-1)
Return the count of items given the shape.
Definition: Utility.cs:83
The BlobCollection contains a list of Blobs.
int Count
Returns the number of items in the collection.
void Reshape(int[] rgShape)
Reshapes all blobs in the collection to the given shape.
void CopyFrom(BlobCollection< T > bSrc, bool bCopyDiff=false)
Copy the data or diff from another BlobCollection into this one.
The Blob is the main holder of data that moves through the Layers of the Net.
Definition: Blob.cs:25
T[] mutable_cpu_data
Get data from the GPU and bring it over to the host, or Set data from the Host and send it over to th...
Definition: Blob.cs:1461
void Reshape(int nNum, int nChannels, int nHeight, int nWidth, bool? bUseHalfSize=null)
DEPRECIATED; use
Definition: Blob.cs:442
void SetParameter(string strName, double dfVal)
Set a blob parameter.
Definition: Blob.cs:233
int count()
Returns the total number of items in the Blob.
Definition: Blob.cs:739
The CudaDnn object is the main interface to the Low-Level Cuda C++ DLL.
Definition: CudaDnn.cs:969
An interface for the units of computation which can be composed into a Net.
Definition: Layer.cs:31
Log m_log
Specifies the Log for output.
Definition: Layer.cs:43
LayerParameter m_param
Specifies the LayerParameter describing the Layer.
Definition: Layer.cs:47
void convert(BlobCollection< T > col)
Convert a collection of blobs from / to half size.
Definition: Layer.cs:535
double Forward(BlobCollection< T > colBottom, BlobCollection< T > colTop)
Given the bottom (input) Blobs, this function computes the top (output) Blobs and the loss.
Definition: Layer.cs:728
float convertF(T df)
Converts a generic to a float value.
Definition: Layer.cs:1359
Phase m_phase
Specifies the Phase under which the Layer is run.
Definition: Layer.cs:51
CudaDnn< T > m_cuda
Specifies the CudaDnn connection to Cuda.
Definition: Layer.cs:39
void Setup(BlobCollection< T > colBottom, BlobCollection< T > colTop)
Implements common Layer setup functionality.
Definition: Layer.cs:439
static Layer< T > Create(CudaDnn< T > cuda, Log log, LayerParameter p, CancelEvent evtCancel, IXDatabaseBase db=null, TransferInput trxinput=null)
Create a new Layer based on the LayerParameter.
Definition: Layer.cs:1468
LayerParameter.LayerType m_type
Specifies the Layer type.
Definition: Layer.cs:35
The InputData is an abstract class used to get training data and tokenize input data.
Definition: Interfaces.cs:113
abstract uint TokenSize
Returns the size of a single token (e.g. 1 for character data)
Definition: Interfaces.cs:138
abstract uint VocabularySize
Returns the size of the vocabulary.
Definition: Interfaces.cs:142
abstract Tuple< float[], float[]> GetData(int nBatchSize, int nBlockSize, InputData trgData, out int[] rgnIdx)
Gets a set of randomly selected source/target data, where the target may be null.
abstract List< int > Tokenize(string str, bool bAddBos, bool bAddEos)
Tokenize an input string using the internal vocabulary.
Random m_random
Specifies the random object made available to the derived classes.
Definition: Interfaces.cs:117
abstract string Detokenize(int nTokIdx, bool bIgnoreBos, bool bIgnoreEos)
Detokenize a single token.
The TextInputData manages character data read in from a text file. Data is tokenized into indexes tha...
override bool GetDataAvailabilityAt(int nIdx, bool bIncludeSrc, bool bIncludeTrg)
Returns true if data is available at the given index.
override string Detokenize(float[] rgfTokIdx, int nStartIdx, int nCount, bool bIgnoreBos, bool bIgnoreEos)
Detokenize an array into a string.
TextInputData(string strSrc, TokenizedDataParameter.VOCABULARY_TYPE vocabType=TokenizedDataParameter.VOCABULARY_TYPE.CHARACTER, int? nRandomSeed=null, string strDebugIndexFile=null, Phase phase=Phase.NONE)
The constructor.
override List< string > RawData
Return the raw data.
override uint TokenSize
The text data token size is a single character.
override uint VocabularySize
Returns the number of unique characters in the data.
override char EOS
Return the special end of sequence character.
override Tuple< float[], float[]> GetData(int nBatchSize, int nBlockSize, InputData trgData, out int[] rgnIdx)
Retrieve random blocks from the source data where the data and target are the same but offset by one ...
override char BOS
Return the special begin of sequence character.
override string Detokenize(int nTokIdx, bool bIgnoreBos, bool bIgnoreEos)
Detokenize a single token.
override Tuple< float[], float[]> GetDataAt(int nBatchSize, int nBlockSize, int[] rgnIdx)
Specifies the GetDataAt method - Not used.
override List< int > Tokenize(string str, bool bAddBos, bool bAddEos)
Tokenize an input string using the internal vocabulary.
The TokenizedDataLayer loads and tokenizes data for a transformer model where data is loaded in the f...
override void Reshape(BlobCollection< T > colBottom, BlobCollection< T > colTop)
Reshape the top based on the parameter batch and block size.
TokenizedDataLayer(CudaDnn< T > cuda, Log log, LayerParameter p, IXDatabaseBase db, CancelEvent evtCancel)
The TokenizedDataLayer constructor.
string Detokenize(float[] rg, int nStartIdx, int nCount, bool bIgnoreBos=true, bool bIgnoreEos=true)
Detokenize a set of tokens from the data specified.
override List< Tuple< string, int, double > > PostProcessLogitsOutput(int nCurIdx, Blob< T > blobLogits, Layer< T > softmax, int nAxis, int nK=1)
Allows post processing the logits output data by converting the logits to and selecting from the prob...
override void LayerSetUp(BlobCollection< T > colBottom, BlobCollection< T > colTop)
Setup the layer.
override int? MaxBottomBlobs
No bottom blobs for the data layer, except when running.
override int? ExactNumTopBlobs
Returns the maximum number of required top (output) Blobs: data, pos, target
override bool PreProcessInput(string str, int? nTokIdx, BlobCollection< T > colBottom=null)
Preproces the input and return as a set of bottom blobs.
override int MinBottomBlobs
Returns the minimum number of bottom blobs.
override void backward(BlobCollection< T > colTop, List< bool > rgbPropagateDown, BlobCollection< T > colBottom)
Not implemented - data Layers do not perform backward..
override void dispose()
Release all internal blobs.
override BlobCollection< T > PreProcessInput(PropertySet customInput, out int nSeqLen, BlobCollection< T > colBottom=null)
Preproces the input and return as a set of bottom blobs.
override bool SupportsPostProcessingLogits
Specifies that this layer supports post processing the logits.
override bool SupportsPreProcessing
Specifies that this layer supports preprocessing.
override void forward(BlobCollection< T > colBottom, BlobCollection< T > colTop)
Run the Forward computation, which fills the data into the top (output) Blobs.
List< int > Tokenize(string str, bool bAddBos, bool bAddEos)
Tokenize an input string using the internal vocabulary.
The VocabularyCharacters class manages the data vocabulary of characters.
The VocabularyWords class manages the data vocabulary of words.
Specifies the base parameter for all layers.
TokenizedDataParameter tokenized_data_param
Returns the parameter set when initialized with LayerType.TOKENIZED_DATA
SoftmaxParameter softmax_param
Returns the parameter set when initialized with LayerType.SOFTMAX
Phase phase
Specifies the Phase for which this LayerParameter is run.
LayerType
Specifies the layer type.
int axis
The axis along which to perform the softmax – may be negative to index from the end (e....
Specifies the parameters for the TokenizedDataLayer.
string debug_index_file
Specifies an optional data index file used for debugging only.
SAMPLE_METHOD sample_method
Specifies the sampling method used when post processing logits (default = ARGMAX).
INPUT_TYPE input_type
Specifies data source input type.
string source
Specifies the data source based on the INPUT_TYPE used. Each dataset has both a training and testing ...
uint block_size
Specifies size of the block.
SAMPLE_METHOD
Defines the sampling method used.
VOCABULARY_TYPE vocabulary_type
Specifies the vocabulary type to use.
int? seed
Specifies the seed used to initialize the random number generator (normally only for testing).
VOCABULARY_TYPE
Defines the vocabulary type to use.
The IXDatabaseBase interface defines the general interface to the in-memory database.
Definition: Interfaces.cs:444
The IVocabulary interface specifies the interface that all Vocabularies implement.
Definition: Interfaces.cs:14
char EOS
Returns the special EOS character.
Definition: Interfaces.cs:26
int[] Tokenize(string str, bool bAddBos, bool bAddEos)
Tokenize a string of data.
int BuildFromString(string strData)
Build the vocabulary from a string.
char BOS
Returns the special BOS character.
Definition: Interfaces.cs:22
int Count
Returns the size of the vocabulary.
Definition: Interfaces.cs:18
string Detokenize(float[] rgf, bool bIgnoreBos, bool bIgnoreEos)
Detokenize an array into a string.
The MyCaffe.basecode contains all generic types used throughout MyCaffe.
Definition: Annotation.cs:12
Phase
Defines the Phase under which to run a Net.
Definition: Interfaces.cs:61
SPECIAL_TOKENS
Specifies the special tokens.
Definition: Interfaces.cs:15
The MyCaffe.common namespace contains common MyCaffe classes.
Definition: BatchInput.cs:8
The MyCaffe.db.image namespace contains all image database related classes.
Definition: Database.cs:18
The MyCaffe.fillers namespace contains all fillers including the Filler class.
The MyCaffe.layers.gpt namespace contains all GPT related layers.
Definition: LayerFactory.cs:15
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