-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Term transformer implementation #759
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
TomFinley
merged 21 commits into
dotnet:master
from
Ivanidzo4ka:ivanidze/Term_Transformer
Sep 4, 2018
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
23170de
first iteration
b7cc054
ctrl+k+d
99b2e2f
some improvments
1e848c5
some more metadata magic
577d62f
fix onnx story
53260d0
RowToRowToRowToRowToRow
058b04c
prepare for review
8c9823d
ColumnBase first
b5dd8a8
Merge branch 'master' into ivanidze/Term_Transformer
2396f86
move to one to one base transformer
98ff3c1
fix saving, conversion
b22a14e
address some comments and clean code
ea270f0
some more changes
72be9d3
more changes
76bcd54
Onnx comments
b9e1473
shuffle codecs, onnx, private
f7e3a12
silly solution
e95cd43
improvments in tests
e3fce58
Merge branch 'master' into ivanidze/Term_Transformer
ec3e5d3
extra line
fa14729
Merge branch 'master' into ivanidze/Term_Transformer
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using Microsoft.ML.Core.Data; | ||
using System.Linq; | ||
|
||
namespace Microsoft.ML.Runtime.Data | ||
{ | ||
public sealed class TermEstimator : IEstimator<TermTransform> | ||
{ | ||
private readonly IHost _host; | ||
private readonly TermTransform.ColumnInfo[] _columns; | ||
public TermEstimator(IHostEnvironment env, string name, string source = null, int maxNumTerms = TermTransform.Defaults.MaxNumTerms, TermTransform.SortOrder sort = TermTransform.Defaults.Sort) : | ||
this(env, new TermTransform.ColumnInfo(name, source ?? name, maxNumTerms, sort)) | ||
{ | ||
} | ||
|
||
public TermEstimator(IHostEnvironment env, params TermTransform.ColumnInfo[] columns) | ||
{ | ||
Contracts.CheckValue(env, nameof(env)); | ||
_host = env.Register(nameof(TermEstimator)); | ||
_columns = columns; | ||
} | ||
|
||
public TermTransform Fit(IDataView input) => new TermTransform(_host, input, _columns); | ||
|
||
public SchemaShape GetOutputSchema(SchemaShape inputSchema) | ||
{ | ||
_host.CheckValue(inputSchema, nameof(inputSchema)); | ||
var result = inputSchema.Columns.ToDictionary(x => x.Name); | ||
foreach (var colInfo in _columns) | ||
{ | ||
var col = inputSchema.FindColumn(colInfo.Input); | ||
|
||
if (col == null) | ||
throw _host.ExceptSchemaMismatch(nameof(inputSchema), "input", colInfo.Input); | ||
|
||
if ((col.ItemType.ItemType.RawKind == default) || !(col.ItemType.IsVector || col.ItemType.IsPrimitive)) | ||
throw _host.ExceptSchemaMismatch(nameof(inputSchema), "input", colInfo.Input); | ||
string[] metadata; | ||
if (col.MetadataKinds.Contains(MetadataUtils.Kinds.SlotNames)) | ||
metadata = new[] { MetadataUtils.Kinds.SlotNames, MetadataUtils.Kinds.KeyValues }; | ||
else | ||
metadata = new[] { MetadataUtils.Kinds.KeyValues }; | ||
result[colInfo.Output] = new SchemaShape.Column(colInfo.Output, col.Kind, NumberType.U4, true, metadata); | ||
} | ||
|
||
return new SchemaShape(result.Values); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can I use SimpleRow? #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose you can
In reply to: 214102719 [](ancestors = 214102719)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A better question is: can you reuse
RowCursor
somehow? Maybe deriveRowCursor
fromRow
or something. It's bad to have two implementations ofGetGetter
In reply to: 214105932 [](ancestors = 214105932,214102719)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's rude to intervene my dialogue with myself!
In reply to: 214106201 [](ancestors = 214106201,214105932,214102719)