-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
TestWiki.cs
53 lines (46 loc) · 1.9 KB
/
TestWiki.cs
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
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VW;
using VW.Labels;
namespace cs_unittest
{
[TestClass]
public class TestWikiClass
{
[TestMethod]
[TestCategory("Vowpal Wabbit")]
public void TestWiki()
{
using (var vw = new VW.VowpalWabbit("-f rcv1.model"))
{
// 1 |f 13:3.9656971e-02 24:3.4781646e-02 69:4.6296168e-02
using (var exampleBuilder = new VW.VowpalWabbitExampleBuilder(vw))
{
// important to dispose the namespace builder at the end, as data is only added to the example
// if there is any feature added to the namespace
using (var ns = exampleBuilder.AddNamespace('f'))
{
var namespaceHash = vw.HashSpace("f");
var featureHash = vw.HashFeature("13", namespaceHash);
ns.AddFeature(featureHash, 8.5609287e-02f);
featureHash = vw.HashFeature("24", namespaceHash);
ns.AddFeature(featureHash, 3.4781646e-02f);
featureHash = vw.HashFeature("69", namespaceHash);
ns.AddFeature(featureHash, 4.6296168e-02f);
}
exampleBuilder.ApplyLabel(new SimpleLabel() { Label = 1 });
// hand over of memory management
using (var example = exampleBuilder.CreateExample())
{
VowpalWabbitExampleValidator.Validate("1 |f 13:8.5609287e-02 24:3.4781646e-02 69:4.6296168e-02", example, VowpalWabbitLabelComparator.Simple);
vw.Learn(example);
}
}
}
}
}
}