Skip to content

Commit c944f54

Browse files
committed
VocabularyProcessor is DEPRECATED, change to another example.
1 parent 6495cac commit c944f54

6 files changed

Lines changed: 39 additions & 5 deletions

File tree

TensorFlow.NET.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TensorFlowNET.Utility", "sr
1313
EndProject
1414
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TensorFlowNET.Visualization", "TensorFlowNET.Visualization\TensorFlowNET.Visualization.csproj", "{4BB2ABD1-635E-41E4-B534-CB5B6A2D754D}"
1515
EndProject
16+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NumSharp.Core", "..\NumSharp\src\NumSharp.Core\NumSharp.Core.csproj", "{E8340C61-12C1-4BEE-A340-403E7C1ACD82}"
17+
EndProject
1618
Global
1719
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1820
Debug|Any CPU = Debug|Any CPU
@@ -39,6 +41,10 @@ Global
3941
{4BB2ABD1-635E-41E4-B534-CB5B6A2D754D}.Debug|Any CPU.Build.0 = Debug|Any CPU
4042
{4BB2ABD1-635E-41E4-B534-CB5B6A2D754D}.Release|Any CPU.ActiveCfg = Release|Any CPU
4143
{4BB2ABD1-635E-41E4-B534-CB5B6A2D754D}.Release|Any CPU.Build.0 = Release|Any CPU
44+
{E8340C61-12C1-4BEE-A340-403E7C1ACD82}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
45+
{E8340C61-12C1-4BEE-A340-403E7C1ACD82}.Debug|Any CPU.Build.0 = Debug|Any CPU
46+
{E8340C61-12C1-4BEE-A340-403E7C1ACD82}.Release|Any CPU.ActiveCfg = Release|Any CPU
47+
{E8340C61-12C1-4BEE-A340-403E7C1ACD82}.Release|Any CPU.Build.0 = Release|Any CPU
4248
EndGlobalSection
4349
GlobalSection(SolutionProperties) = preSolution
4450
HideSolutionNode = FALSE
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace Tensorflow.Contrib.Learn.Preprocessing
6+
{
7+
public class VocabularyProcessor
8+
{
9+
private int _max_document_length;
10+
private int _min_frequency;
11+
12+
public VocabularyProcessor(int max_document_length,
13+
int min_frequency)
14+
{
15+
_max_document_length = max_document_length;
16+
_min_frequency = min_frequency;
17+
}
18+
}
19+
}

src/TensorFlowNET.Core/TensorFlowNET.Core.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,8 @@ Fixed import name scope issue.</PackageReleaseNotes>
5151
<Content CopyToOutputDirectory="PreserveNewest" Include="./runtimes/win-x64/native/tensorflow.dll" Link="tensorflow.dll" Pack="true" PackagePath="runtimes/win-x64/native/tensorflow.dll" />
5252
</ItemGroup>
5353

54+
<ItemGroup>
55+
<ProjectReference Include="..\..\..\NumSharp\src\NumSharp.Core\NumSharp.Core.csproj" />
56+
</ItemGroup>
57+
5458
</Project>

test/TensorFlowNET.Examples/CnnTextClassification/CnnTextTrain.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using NumSharp.Core;
22
using System;
33
using System.Collections.Generic;
4+
using System.Linq;
45
using System.Text;
56
using Tensorflow;
67

@@ -46,7 +47,11 @@ public void Run()
4647

4748
public (NDArray, NDArray, NDArray, NDArray, NDArray) preprocess()
4849
{
49-
DataHelpers.load_data_and_labels(positive_data_file, negative_data_file);
50+
var (x_text, y) = DataHelpers.load_data_and_labels(positive_data_file, negative_data_file);
51+
52+
// Build vocabulary
53+
int max_document_length = x_text.Select(x => x.Split(' ').Length).Max();
54+
var vocab_processor = learn.preprocessing.VocabularyProcessor(max_document_length)
5055
throw new NotImplementedException("");
5156
}
5257
}

test/TensorFlowNET.Examples/CnnTextClassification/DataHelpers.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class DataHelpers
1717
/// <param name="positive_data_file"></param>
1818
/// <param name="negative_data_file"></param>
1919
/// <returns></returns>
20-
public static (NDArray, NDArray) load_data_and_labels(string positive_data_file, string negative_data_file)
20+
public static (string[], NDArray) load_data_and_labels(string positive_data_file, string negative_data_file)
2121
{
2222
Directory.CreateDirectory("CnnTextClassification");
2323
Utility.Web.Download(positive_data_file, "CnnTextClassification/rt-polarity.pos");
@@ -39,9 +39,8 @@ public static (NDArray, NDArray) load_data_and_labels(string positive_data_file,
3939

4040
var positive_labels = positive_examples.Select(x => new int[2] { 0, 1 }).ToArray();
4141
var negative_labels = negative_examples.Select(x => new int[2] { 1, 0 }).ToArray();
42-
// var y = np.
43-
// return (x_text, y);
44-
throw new NotImplementedException("load_data_and_labels");
42+
var y = np.concatenate(new int[][][] { positive_labels, negative_labels });
43+
return (x_text.ToArray(), y);
4544
}
4645

4746
private static string clean_str(string str)

test/TensorFlowNET.Examples/TensorFlowNET.Examples.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
</ItemGroup>
1212

1313
<ItemGroup>
14+
<ProjectReference Include="..\..\..\NumSharp\src\NumSharp.Core\NumSharp.Core.csproj" />
1415
<ProjectReference Include="..\..\src\TensorFlowNET.Core\TensorFlowNET.Core.csproj" />
1516
<ProjectReference Include="..\..\src\TensorFlowNET.Utility\TensorFlowNET.Utility.csproj" />
1617
</ItemGroup>

0 commit comments

Comments
 (0)