Convert LdaTransform to IEstimator/ITransformer API - #1410

Merged
shauheen merged 38 commits into
dotnet:masterfrom
abgoswam:abgoswam/LDA_conversion
Nov 20, 2018
Merged

Convert LdaTransform to IEstimator/ITransformer API#1410
shauheen merged 38 commits into
dotnet:masterfrom
abgoswam:abgoswam/LDA_conversion

Conversation

@abgoswam

@abgoswamabgoswam commented Oct 27, 2018

Copy link
Copy Markdown
Member

This PR converts LdaTransform to the IEstimator/ITransformer API paradigm (a work item related to #754)

  • LdaTransform is now subclass of OneToOneTransformerBase
  • Deleted the previous wrapped version.
  • Added pigsty extensions
  • Added onFit delegate to return LdaState info to user

Created separate issue #1411 for providing a convenient way of providing LDA topic summary info to the user

using Microsoft.ML.Runtime.Internal.Utilities;
using Microsoft.ML.Runtime.Model;
using Microsoft.ML.Runtime.TextAnalytics;
using Microsoft.ML.Core.Data;

@Ivanidzo4kaIvanidzo4kaOct 29, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ctrl+R+G (aka sort using) #Closed


// The type T asociated with the delegate will be the actual value type once #863 goes in.
// However, until such time as #863 goes in, it would be too awkward to attempt to extract the metadata.
// For now construct the useless object then pass it into the delegate.

@Ivanidzo4kaIvanidzo4kaOct 31, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this comment doesn't seems right. #Resolved

[assembly: LoadableClass(typeof(IRowMapper), typeof(LdaTransform), null, typeof(SignatureLoadRowMapper),
"Latent Dirichlet Allocation Transform", LdaTransform.LoaderSignature)]

namespace Microsoft.ML.Runtime.TextAnalytics

@Ivanidzo4kaIvanidzo4kaOct 31, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Runtime [](start = 23, length = 7)

Can you merge with master, I'm sure Senja changed this namespace to something better. #Resolved

try
{
var lda = new LdaTransform(Env, args, srcView);
var lda = LdaTransform.Create(Env, args, srcView);

@Ivanidzo4kaIvanidzo4kaOct 31, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LdaTransform [](start = 26, length = 12)

Can you switch to estimator call?
Basically var lda = LdaEstimator(env, cols).Fit(srcView).Transform(scrView); #Resolved

/// <param name="numSummaryTermPerTopic">The number of words to summarize the topic</param>
/// <param name="numBurninIterations">The number of burn-in iterations</param>
/// <param name="resetRandomGenerator">Reset the random number generator for each document</param>
/// <param name="onFit">Called upon fitting with the learnt enumeration on the dataset.</param>

@Ivanidzo4kaIvanidzo4kaOct 31, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sprinkle it with dots at the end of sentence. #Resolved

Contracts.Assert(0 <= iinfo && iinfo < _parent.ColumnPairs.Length);
disposer = null;

var test = TestType(_srcTypes[iinfo]);

@abgoswamabgoswamNov 5, 2018

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TestType [](start = 27, length = 8)

@ivan. Should we put this check here v/s putting it in the Mapper constructor ? Does it make a difference ? #Closed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It make difference at what point it will fail. I would prefer to test types in constructor.


In reply to: 230899143 [](ancestors = 230899143)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer not to have TestType idiom please


In reply to: 232105072 [](ancestors = 232105072,230899143)

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if column type in incorrect we now throw ExceptSchemaMismatch


In reply to: 232437787 [](ancestors = 232437787,232105072,230899143)

private struct Config
{
public readonly int NumTopic;
public readonly Single AlphaSum;

@wschinwschinNov 6, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
publicreadonlySingleAlphaSum;
publicreadonlyfloatAlphaSum;
``` #Resolved

{
public readonly int NumTopic;
public readonly Single AlphaSum;
public readonly Single Beta;

@wschinwschinNov 6, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
publicreadonlySingleBeta;
publicreadonlyfloatBeta;
``` #Resolved

using System.Text;
using Xunit;
using Xunit.Abstractions;
using static Microsoft.ML.Transforms.Text.LdaTransform;

@artidoroartidoroNov 6, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sort the usings. #Resolved

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Control+R Control+G (remove and sort Using) gives this order itself


In reply to: 231324047 [](ancestors = 231324047)

}

/// <include file='doc.xml' path='doc/members/member[@name="LightLDA"]/*' />
/// <param name="input">The column to apply to.</param>

@wschinwschinNov 6, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you describe what this transform is doing briefly? #Resolved

/// <param name="onFit">Called upon fitting with the learnt enumeration on the dataset.</param>
public static Vector<float> ToLdaTopicVector(this Vector<float> input,
int numTopic = LdaEstimator.Defaults.NumTopic,
Single alphaSum = LdaEstimator.Defaults.AlphaSum,

@wschinwschinNov 6, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
SinglealphaSum=LdaEstimator.Defaults.AlphaSum,
floatalphaSum=LdaEstimator.Defaults.AlphaSum,
``` #Resolved

public static Vector<float> ToLdaTopicVector(this Vector<float> input,
int numTopic = LdaEstimator.Defaults.NumTopic,
Single alphaSum = LdaEstimator.Defaults.AlphaSum,
Single beta = LdaEstimator.Defaults.Beta,

@wschinwschinNov 6, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Singlebeta=LdaEstimator.Defaults.Beta,
floatbeta=LdaEstimator.Defaults.Beta,
``` #Resolved

@artidoro

artidoro commented Nov 7, 2018

Copy link
Copy Markdown
Contributor

Could you add mlcontext extensions?
You can follow this PR as an example: #1524. The whitening PR also does that. #Resolved

}

private sealed class ColInfoEx
public sealed class ColumnInfo

@artidoroartidoroNov 7, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not combine this with transformInfo? You can just add this public constructor and change the name to columnInfo, while keeping the other methods internal/private. #Resolved

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any reason why you can't delete TransformInfo class and use ColumnInfo instead.


In reply to: 231632966 [](ancestors = 231632966)

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


In reply to: 232104746 [](ancestors = 232104746,231632966)

getSrc(ref src);
lda.Output(in src, ref dst, numBurninIter, reset);
};
return new LdaTransform(_host, input, _columns);

@artidoroartidoroNov 7, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

=> #Closed

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


In reply to: 231635318 [](ancestors = 231635318)

}
using (var ch = Host.Start("Train"))
{
Train(ch, input, _ldas);

@artidoroartidoroNov 7, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Train [](start = 16, length = 5)

Pete suggested that we make training a private static method in the transform, and that we have a constructor for the transform that will accept the trained parameters as an input.

This should make it easier to allow initialization of the transform using parameters coming from an external training routine. It is not something that we are exposing now, however.

This allows the transform to only keep the fields storing trained parameters. For example _types should no longer be needed as a field in the transform. #Closed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have implemented something like this for whitening.


In reply to: 231639657 [](ancestors = 231639657)

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed. thanks for giving the context about this approach.


In reply to: 231640188 [](ancestors = 231640188,231639657)


NumThread = item.NumThreads ?? args.NumThreads ?? 0;
ectx.CheckUserArg(NumThread >= 0, nameof(item.NumThreads), "Must be positive or zero.");
public sealed class LdaState : IDisposable

@artidoroartidoroNov 7, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public [](start = 8, length = 6)

Can this be made internal/private? #Closed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like some 'LDA guts' and should under no circumstances be exposed to the user.


In reply to: 231641222 [](ancestors = 231641222)

@abgoswamabgoswamNov 11, 2018

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made this internal. Instead added a class LdaTopicSummary to provide topic summary information back to users (when needed)


In reply to: 232437742 [](ancestors = 232437742,231641222)

@abgoswam

abgoswam commented Nov 15, 2018

Copy link
Copy Markdown
MemberAuthor

@Zruty0 I have addressed your PR comments. Could you kindly take a look ? #Resolved

@shauheen

shauheen commented Nov 19, 2018

Copy link
Copy Markdown
Contributor

ping @Zruty0 #Resolved

using System;
using System.Collections.Generic;

namespace Microsoft.ML.Transforms.Text

@Ivanidzo4kaIvanidzo4kaNov 19, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Microsoft.ML.Transforms.Text [](start = 10, length = 28)

Pete will ask you to put static extensions into Microsoft.ML.StaticPipe; #Closed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I sure will


In reply to: 234771139 [](ancestors = 234771139)

ectx.CheckUserArg(NumBurninIter >= 0, nameof(item.NumBurninIterations), "Must be non-negative.");
Contracts.CheckValue(input, nameof(input));
Contracts.CheckValueOrNull(output);
Contracts.CheckUserArg(numTopic > 0, nameof(numTopic), "Must be positive.");

@Zruty0Zruty0Nov 20, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CheckUserArg [](start = 26, length = 12)

Unless parsing command line, use CheckParam instead of CheckUserArg #Resolved

ctx.CheckAtModel(GetVersionInfo());
h.CheckValue(input, nameof(input));
// For each topic, provide information about the (item, score) pairs.
public readonly Dictionary<int, List<Tuple<int, float>>> ItemScoresPerTopic;

@Zruty0Zruty0Nov 20, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

List<Tuple<int, float> [](start = 44, length = 22)

Tuple<int, float> -> (int Item, float Score) (use named tuple instead of tuples)
List -> `ImmutableArray
#Resolved

ctx.CheckAtModel(GetVersionInfo());
h.CheckValue(input, nameof(input));
// For each topic, provide information about the (item, score) pairs.
public readonly Dictionary<int, List<Tuple<int, float>>> ItemScoresPerTopic;

@Zruty0Zruty0Nov 20, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the int key in this dictionary? Is it a sequential integer? If yes, make it into ImmutableArray. If it's not a sequential integer, describe what it is, and make it into an IReadOnlyDictionary #Resolved

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

made it ImmutableArray since its a sequential integer


In reply to: 234857025 [](ancestors = 234857025)

@Zruty0Zruty0 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@Zruty0

Copy link
Copy Markdown
Contributor

Approval conditional on fixing all the remaining open comments :)


/// <summary>
/// Initializes a new instance of <see cref="LatentDirichletAllocationEstimator"/>.
/// </summary>

@Ivanidzo4kaIvanidzo4kaNov 20, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use summary form method above.
It should be user friendly. #Resolved

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


In reply to: 235162180 [](ancestors = 235162180)

}

ResetRandomGenerator = item.ResetRandomGenerator ?? args.ResetRandomGenerator;
internal ColumnInfo(Column item, Arguments args)

@Ivanidzo4kaIvanidzo4kaNov 20, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

internal ColumnInfo(Column item, Arguments args) [](start = 12, length = 48)

you can just call constructor above, and that way you don't need to duplicate code.
internal ColumnInfo(Column item, Arguments args): this( item.Source, item.Name, args.NumTopic, ....)
#Resolved

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


In reply to: 235162967 [](ancestors = 235162967)

}
}

public const string LoaderSignature = "LdaTransform";

@Ivanidzo4kaIvanidzo4kaNov 20, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public [](start = 8, length = 6)

internal #Resolved

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


In reply to: 235163681 [](ancestors = 235163681)


// The following call fails because of the following issue
// https://github.com/dotnet/machinelearning/issues/969
// In this test it manifests because of the WordBagEstimator in the estimator chain

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would happen if you uncomment this?
I've recently convert WordBag to estimator so it should work properly.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I uncomment this, I get an error

Schema mismatch for input column 'text': expected Text, got R4 Parameter name: inputSchema

The WordBagWorkout test still comments out the TestEstimatorCore (line #186 above) .


In reply to: 235166598 [](ancestors = 235166598)

@Ivanidzo4kaIvanidzo4ka left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@shauheen
shauheen merged commit 1a9e7aa into dotnet:masterNov 20, 2018
@abgoswam
abgoswam deleted the abgoswam/LDA_conversion branch January 13, 2019 18:12
@ghostghost locked as resolved and limited conversation to collaborators Mar 27, 2022
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants

@abgoswam@artidoro@Zruty0@shauheen@Ivanidzo4ka@wschin@sfilipi
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all \u003cpre\u003e\u003ccode\u003e blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks"); } } catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); } })(); (function(){ try { var __m = "github.com"; var __re = new RegExp('^' + "github\\.com" + '
Skip to content

Convert LdaTransform to IEstimator/ITransformer API - #1410

Merged
shauheen merged 38 commits into
dotnet:masterfrom
abgoswam:abgoswam/LDA_conversion
Nov 20, 2018
Merged

Convert LdaTransform to IEstimator/ITransformer API#1410
shauheen merged 38 commits into
dotnet:masterfrom
abgoswam:abgoswam/LDA_conversion

Conversation

@abgoswam

@abgoswamabgoswam commented Oct 27, 2018

Copy link
Copy Markdown
Member

This PR converts LdaTransform to the IEstimator/ITransformer API paradigm (a work item related to #754)

  • LdaTransform is now subclass of OneToOneTransformerBase
  • Deleted the previous wrapped version.
  • Added pigsty extensions
  • Added onFit delegate to return LdaState info to user

Created separate issue #1411 for providing a convenient way of providing LDA topic summary info to the user

using Microsoft.ML.Runtime.Internal.Utilities;
using Microsoft.ML.Runtime.Model;
using Microsoft.ML.Runtime.TextAnalytics;
using Microsoft.ML.Core.Data;

@Ivanidzo4kaIvanidzo4kaOct 29, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ctrl+R+G (aka sort using) #Closed


// The type T asociated with the delegate will be the actual value type once #863 goes in.
// However, until such time as #863 goes in, it would be too awkward to attempt to extract the metadata.
// For now construct the useless object then pass it into the delegate.

@Ivanidzo4kaIvanidzo4kaOct 31, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this comment doesn't seems right. #Resolved

[assembly: LoadableClass(typeof(IRowMapper), typeof(LdaTransform), null, typeof(SignatureLoadRowMapper),
"Latent Dirichlet Allocation Transform", LdaTransform.LoaderSignature)]

namespace Microsoft.ML.Runtime.TextAnalytics

@Ivanidzo4kaIvanidzo4kaOct 31, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Runtime [](start = 23, length = 7)

Can you merge with master, I'm sure Senja changed this namespace to something better. #Resolved

try
{
var lda = new LdaTransform(Env, args, srcView);
var lda = LdaTransform.Create(Env, args, srcView);

@Ivanidzo4kaIvanidzo4kaOct 31, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LdaTransform [](start = 26, length = 12)

Can you switch to estimator call?
Basically var lda = LdaEstimator(env, cols).Fit(srcView).Transform(scrView); #Resolved

/// <param name="numSummaryTermPerTopic">The number of words to summarize the topic</param>
/// <param name="numBurninIterations">The number of burn-in iterations</param>
/// <param name="resetRandomGenerator">Reset the random number generator for each document</param>
/// <param name="onFit">Called upon fitting with the learnt enumeration on the dataset.</param>

@Ivanidzo4kaIvanidzo4kaOct 31, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sprinkle it with dots at the end of sentence. #Resolved

Contracts.Assert(0 <= iinfo && iinfo < _parent.ColumnPairs.Length);
disposer = null;

var test = TestType(_srcTypes[iinfo]);

@abgoswamabgoswamNov 5, 2018

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TestType [](start = 27, length = 8)

@ivan. Should we put this check here v/s putting it in the Mapper constructor ? Does it make a difference ? #Closed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It make difference at what point it will fail. I would prefer to test types in constructor.


In reply to: 230899143 [](ancestors = 230899143)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer not to have TestType idiom please


In reply to: 232105072 [](ancestors = 232105072,230899143)

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if column type in incorrect we now throw ExceptSchemaMismatch


In reply to: 232437787 [](ancestors = 232437787,232105072,230899143)

private struct Config
{
public readonly int NumTopic;
public readonly Single AlphaSum;

@wschinwschinNov 6, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
publicreadonlySingleAlphaSum;
publicreadonlyfloatAlphaSum;
``` #Resolved

{
public readonly int NumTopic;
public readonly Single AlphaSum;
public readonly Single Beta;

@wschinwschinNov 6, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
publicreadonlySingleBeta;
publicreadonlyfloatBeta;
``` #Resolved

using System.Text;
using Xunit;
using Xunit.Abstractions;
using static Microsoft.ML.Transforms.Text.LdaTransform;

@artidoroartidoroNov 6, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sort the usings. #Resolved

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Control+R Control+G (remove and sort Using) gives this order itself


In reply to: 231324047 [](ancestors = 231324047)

}

/// <include file='doc.xml' path='doc/members/member[@name="LightLDA"]/*' />
/// <param name="input">The column to apply to.</param>

@wschinwschinNov 6, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you describe what this transform is doing briefly? #Resolved

/// <param name="onFit">Called upon fitting with the learnt enumeration on the dataset.</param>
public static Vector<float> ToLdaTopicVector(this Vector<float> input,
int numTopic = LdaEstimator.Defaults.NumTopic,
Single alphaSum = LdaEstimator.Defaults.AlphaSum,

@wschinwschinNov 6, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
SinglealphaSum=LdaEstimator.Defaults.AlphaSum,
floatalphaSum=LdaEstimator.Defaults.AlphaSum,
``` #Resolved

public static Vector<float> ToLdaTopicVector(this Vector<float> input,
int numTopic = LdaEstimator.Defaults.NumTopic,
Single alphaSum = LdaEstimator.Defaults.AlphaSum,
Single beta = LdaEstimator.Defaults.Beta,

@wschinwschinNov 6, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Singlebeta=LdaEstimator.Defaults.Beta,
floatbeta=LdaEstimator.Defaults.Beta,
``` #Resolved

@artidoro

artidoro commented Nov 7, 2018

Copy link
Copy Markdown
Contributor

Could you add mlcontext extensions?
You can follow this PR as an example: #1524. The whitening PR also does that. #Resolved

}

private sealed class ColInfoEx
public sealed class ColumnInfo

@artidoroartidoroNov 7, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not combine this with transformInfo? You can just add this public constructor and change the name to columnInfo, while keeping the other methods internal/private. #Resolved

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any reason why you can't delete TransformInfo class and use ColumnInfo instead.


In reply to: 231632966 [](ancestors = 231632966)

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


In reply to: 232104746 [](ancestors = 232104746,231632966)

getSrc(ref src);
lda.Output(in src, ref dst, numBurninIter, reset);
};
return new LdaTransform(_host, input, _columns);

@artidoroartidoroNov 7, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

=> #Closed

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


In reply to: 231635318 [](ancestors = 231635318)

}
using (var ch = Host.Start("Train"))
{
Train(ch, input, _ldas);

@artidoroartidoroNov 7, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Train [](start = 16, length = 5)

Pete suggested that we make training a private static method in the transform, and that we have a constructor for the transform that will accept the trained parameters as an input.

This should make it easier to allow initialization of the transform using parameters coming from an external training routine. It is not something that we are exposing now, however.

This allows the transform to only keep the fields storing trained parameters. For example _types should no longer be needed as a field in the transform. #Closed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have implemented something like this for whitening.


In reply to: 231639657 [](ancestors = 231639657)

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed. thanks for giving the context about this approach.


In reply to: 231640188 [](ancestors = 231640188,231639657)


NumThread = item.NumThreads ?? args.NumThreads ?? 0;
ectx.CheckUserArg(NumThread >= 0, nameof(item.NumThreads), "Must be positive or zero.");
public sealed class LdaState : IDisposable

@artidoroartidoroNov 7, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public [](start = 8, length = 6)

Can this be made internal/private? #Closed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like some 'LDA guts' and should under no circumstances be exposed to the user.


In reply to: 231641222 [](ancestors = 231641222)

@abgoswamabgoswamNov 11, 2018

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made this internal. Instead added a class LdaTopicSummary to provide topic summary information back to users (when needed)


In reply to: 232437742 [](ancestors = 232437742,231641222)

@abgoswam

abgoswam commented Nov 15, 2018

Copy link
Copy Markdown
MemberAuthor

@Zruty0 I have addressed your PR comments. Could you kindly take a look ? #Resolved

@shauheen

shauheen commented Nov 19, 2018

Copy link
Copy Markdown
Contributor

ping @Zruty0 #Resolved

using System;
using System.Collections.Generic;

namespace Microsoft.ML.Transforms.Text

@Ivanidzo4kaIvanidzo4kaNov 19, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Microsoft.ML.Transforms.Text [](start = 10, length = 28)

Pete will ask you to put static extensions into Microsoft.ML.StaticPipe; #Closed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I sure will


In reply to: 234771139 [](ancestors = 234771139)

ectx.CheckUserArg(NumBurninIter >= 0, nameof(item.NumBurninIterations), "Must be non-negative.");
Contracts.CheckValue(input, nameof(input));
Contracts.CheckValueOrNull(output);
Contracts.CheckUserArg(numTopic > 0, nameof(numTopic), "Must be positive.");

@Zruty0Zruty0Nov 20, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CheckUserArg [](start = 26, length = 12)

Unless parsing command line, use CheckParam instead of CheckUserArg #Resolved

ctx.CheckAtModel(GetVersionInfo());
h.CheckValue(input, nameof(input));
// For each topic, provide information about the (item, score) pairs.
public readonly Dictionary<int, List<Tuple<int, float>>> ItemScoresPerTopic;

@Zruty0Zruty0Nov 20, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

List<Tuple<int, float> [](start = 44, length = 22)

Tuple<int, float> -> (int Item, float Score) (use named tuple instead of tuples)
List -> `ImmutableArray
#Resolved

ctx.CheckAtModel(GetVersionInfo());
h.CheckValue(input, nameof(input));
// For each topic, provide information about the (item, score) pairs.
public readonly Dictionary<int, List<Tuple<int, float>>> ItemScoresPerTopic;

@Zruty0Zruty0Nov 20, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the int key in this dictionary? Is it a sequential integer? If yes, make it into ImmutableArray. If it's not a sequential integer, describe what it is, and make it into an IReadOnlyDictionary #Resolved

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

made it ImmutableArray since its a sequential integer


In reply to: 234857025 [](ancestors = 234857025)

@Zruty0Zruty0 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@Zruty0

Copy link
Copy Markdown
Contributor

Approval conditional on fixing all the remaining open comments :)


/// <summary>
/// Initializes a new instance of <see cref="LatentDirichletAllocationEstimator"/>.
/// </summary>

@Ivanidzo4kaIvanidzo4kaNov 20, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use summary form method above.
It should be user friendly. #Resolved

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


In reply to: 235162180 [](ancestors = 235162180)

}

ResetRandomGenerator = item.ResetRandomGenerator ?? args.ResetRandomGenerator;
internal ColumnInfo(Column item, Arguments args)

@Ivanidzo4kaIvanidzo4kaNov 20, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

internal ColumnInfo(Column item, Arguments args) [](start = 12, length = 48)

you can just call constructor above, and that way you don't need to duplicate code.
internal ColumnInfo(Column item, Arguments args): this( item.Source, item.Name, args.NumTopic, ....)
#Resolved

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


In reply to: 235162967 [](ancestors = 235162967)

}
}

public const string LoaderSignature = "LdaTransform";

@Ivanidzo4kaIvanidzo4kaNov 20, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public [](start = 8, length = 6)

internal #Resolved

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


In reply to: 235163681 [](ancestors = 235163681)


// The following call fails because of the following issue
// https://github.com/dotnet/machinelearning/issues/969
// In this test it manifests because of the WordBagEstimator in the estimator chain

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would happen if you uncomment this?
I've recently convert WordBag to estimator so it should work properly.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I uncomment this, I get an error

Schema mismatch for input column 'text': expected Text, got R4 Parameter name: inputSchema

The WordBagWorkout test still comments out the TestEstimatorCore (line #186 above) .


In reply to: 235166598 [](ancestors = 235166598)

@Ivanidzo4kaIvanidzo4ka left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@shauheen
shauheen merged commit 1a9e7aa into dotnet:masterNov 20, 2018
@abgoswam
abgoswam deleted the abgoswam/LDA_conversion branch January 13, 2019 18:12
@ghostghost locked as resolved and limited conversation to collaborators Mar 27, 2022
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants

@abgoswam@artidoro@Zruty0@shauheen@Ivanidzo4ka@wschin@sfilipi
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Convert LdaTransform to IEstimator/ITransformer API - #1410

Merged
shauheen merged 38 commits into
dotnet:masterfrom
abgoswam:abgoswam/LDA_conversion
Nov 20, 2018
Merged

Convert LdaTransform to IEstimator/ITransformer API#1410
shauheen merged 38 commits into
dotnet:masterfrom
abgoswam:abgoswam/LDA_conversion

Conversation

@abgoswam

@abgoswamabgoswam commented Oct 27, 2018

Copy link
Copy Markdown
Member

This PR converts LdaTransform to the IEstimator/ITransformer API paradigm (a work item related to #754)

  • LdaTransform is now subclass of OneToOneTransformerBase
  • Deleted the previous wrapped version.
  • Added pigsty extensions
  • Added onFit delegate to return LdaState info to user

Created separate issue #1411 for providing a convenient way of providing LDA topic summary info to the user

using Microsoft.ML.Runtime.Internal.Utilities;
using Microsoft.ML.Runtime.Model;
using Microsoft.ML.Runtime.TextAnalytics;
using Microsoft.ML.Core.Data;

@Ivanidzo4kaIvanidzo4kaOct 29, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ctrl+R+G (aka sort using) #Closed


// The type T asociated with the delegate will be the actual value type once #863 goes in.
// However, until such time as #863 goes in, it would be too awkward to attempt to extract the metadata.
// For now construct the useless object then pass it into the delegate.

@Ivanidzo4kaIvanidzo4kaOct 31, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this comment doesn't seems right. #Resolved

[assembly: LoadableClass(typeof(IRowMapper), typeof(LdaTransform), null, typeof(SignatureLoadRowMapper),
"Latent Dirichlet Allocation Transform", LdaTransform.LoaderSignature)]

namespace Microsoft.ML.Runtime.TextAnalytics

@Ivanidzo4kaIvanidzo4kaOct 31, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Runtime [](start = 23, length = 7)

Can you merge with master, I'm sure Senja changed this namespace to something better. #Resolved

try
{
var lda = new LdaTransform(Env, args, srcView);
var lda = LdaTransform.Create(Env, args, srcView);

@Ivanidzo4kaIvanidzo4kaOct 31, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LdaTransform [](start = 26, length = 12)

Can you switch to estimator call?
Basically var lda = LdaEstimator(env, cols).Fit(srcView).Transform(scrView); #Resolved

/// <param name="numSummaryTermPerTopic">The number of words to summarize the topic</param>
/// <param name="numBurninIterations">The number of burn-in iterations</param>
/// <param name="resetRandomGenerator">Reset the random number generator for each document</param>
/// <param name="onFit">Called upon fitting with the learnt enumeration on the dataset.</param>

@Ivanidzo4kaIvanidzo4kaOct 31, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sprinkle it with dots at the end of sentence. #Resolved

Contracts.Assert(0 <= iinfo && iinfo < _parent.ColumnPairs.Length);
disposer = null;

var test = TestType(_srcTypes[iinfo]);

@abgoswamabgoswamNov 5, 2018

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TestType [](start = 27, length = 8)

@ivan. Should we put this check here v/s putting it in the Mapper constructor ? Does it make a difference ? #Closed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It make difference at what point it will fail. I would prefer to test types in constructor.


In reply to: 230899143 [](ancestors = 230899143)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer not to have TestType idiom please


In reply to: 232105072 [](ancestors = 232105072,230899143)

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if column type in incorrect we now throw ExceptSchemaMismatch


In reply to: 232437787 [](ancestors = 232437787,232105072,230899143)

private struct Config
{
public readonly int NumTopic;
public readonly Single AlphaSum;

@wschinwschinNov 6, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
publicreadonlySingleAlphaSum;
publicreadonlyfloatAlphaSum;
``` #Resolved

{
public readonly int NumTopic;
public readonly Single AlphaSum;
public readonly Single Beta;

@wschinwschinNov 6, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
publicreadonlySingleBeta;
publicreadonlyfloatBeta;
``` #Resolved

using System.Text;
using Xunit;
using Xunit.Abstractions;
using static Microsoft.ML.Transforms.Text.LdaTransform;

@artidoroartidoroNov 6, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sort the usings. #Resolved

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Control+R Control+G (remove and sort Using) gives this order itself


In reply to: 231324047 [](ancestors = 231324047)

}

/// <include file='doc.xml' path='doc/members/member[@name="LightLDA"]/*' />
/// <param name="input">The column to apply to.</param>

@wschinwschinNov 6, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you describe what this transform is doing briefly? #Resolved

/// <param name="onFit">Called upon fitting with the learnt enumeration on the dataset.</param>
public static Vector<float> ToLdaTopicVector(this Vector<float> input,
int numTopic = LdaEstimator.Defaults.NumTopic,
Single alphaSum = LdaEstimator.Defaults.AlphaSum,

@wschinwschinNov 6, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
SinglealphaSum=LdaEstimator.Defaults.AlphaSum,
floatalphaSum=LdaEstimator.Defaults.AlphaSum,
``` #Resolved

public static Vector<float> ToLdaTopicVector(this Vector<float> input,
int numTopic = LdaEstimator.Defaults.NumTopic,
Single alphaSum = LdaEstimator.Defaults.AlphaSum,
Single beta = LdaEstimator.Defaults.Beta,

@wschinwschinNov 6, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Singlebeta=LdaEstimator.Defaults.Beta,
floatbeta=LdaEstimator.Defaults.Beta,
``` #Resolved

@artidoro

artidoro commented Nov 7, 2018

Copy link
Copy Markdown
Contributor

Could you add mlcontext extensions?
You can follow this PR as an example: #1524. The whitening PR also does that. #Resolved

}

private sealed class ColInfoEx
public sealed class ColumnInfo

@artidoroartidoroNov 7, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not combine this with transformInfo? You can just add this public constructor and change the name to columnInfo, while keeping the other methods internal/private. #Resolved

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any reason why you can't delete TransformInfo class and use ColumnInfo instead.


In reply to: 231632966 [](ancestors = 231632966)

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


In reply to: 232104746 [](ancestors = 232104746,231632966)

getSrc(ref src);
lda.Output(in src, ref dst, numBurninIter, reset);
};
return new LdaTransform(_host, input, _columns);

@artidoroartidoroNov 7, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

=> #Closed

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


In reply to: 231635318 [](ancestors = 231635318)

}
using (var ch = Host.Start("Train"))
{
Train(ch, input, _ldas);

@artidoroartidoroNov 7, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Train [](start = 16, length = 5)

Pete suggested that we make training a private static method in the transform, and that we have a constructor for the transform that will accept the trained parameters as an input.

This should make it easier to allow initialization of the transform using parameters coming from an external training routine. It is not something that we are exposing now, however.

This allows the transform to only keep the fields storing trained parameters. For example _types should no longer be needed as a field in the transform. #Closed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have implemented something like this for whitening.


In reply to: 231639657 [](ancestors = 231639657)

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed. thanks for giving the context about this approach.


In reply to: 231640188 [](ancestors = 231640188,231639657)


NumThread = item.NumThreads ?? args.NumThreads ?? 0;
ectx.CheckUserArg(NumThread >= 0, nameof(item.NumThreads), "Must be positive or zero.");
public sealed class LdaState : IDisposable

@artidoroartidoroNov 7, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public [](start = 8, length = 6)

Can this be made internal/private? #Closed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like some 'LDA guts' and should under no circumstances be exposed to the user.


In reply to: 231641222 [](ancestors = 231641222)

@abgoswamabgoswamNov 11, 2018

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made this internal. Instead added a class LdaTopicSummary to provide topic summary information back to users (when needed)


In reply to: 232437742 [](ancestors = 232437742,231641222)

@abgoswam

abgoswam commented Nov 15, 2018

Copy link
Copy Markdown
MemberAuthor

@Zruty0 I have addressed your PR comments. Could you kindly take a look ? #Resolved

@shauheen

shauheen commented Nov 19, 2018

Copy link
Copy Markdown
Contributor

ping @Zruty0 #Resolved

using System;
using System.Collections.Generic;

namespace Microsoft.ML.Transforms.Text

@Ivanidzo4kaIvanidzo4kaNov 19, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Microsoft.ML.Transforms.Text [](start = 10, length = 28)

Pete will ask you to put static extensions into Microsoft.ML.StaticPipe; #Closed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I sure will


In reply to: 234771139 [](ancestors = 234771139)

ectx.CheckUserArg(NumBurninIter >= 0, nameof(item.NumBurninIterations), "Must be non-negative.");
Contracts.CheckValue(input, nameof(input));
Contracts.CheckValueOrNull(output);
Contracts.CheckUserArg(numTopic > 0, nameof(numTopic), "Must be positive.");

@Zruty0Zruty0Nov 20, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CheckUserArg [](start = 26, length = 12)

Unless parsing command line, use CheckParam instead of CheckUserArg #Resolved

ctx.CheckAtModel(GetVersionInfo());
h.CheckValue(input, nameof(input));
// For each topic, provide information about the (item, score) pairs.
public readonly Dictionary<int, List<Tuple<int, float>>> ItemScoresPerTopic;

@Zruty0Zruty0Nov 20, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

List<Tuple<int, float> [](start = 44, length = 22)

Tuple<int, float> -> (int Item, float Score) (use named tuple instead of tuples)
List -> `ImmutableArray
#Resolved

ctx.CheckAtModel(GetVersionInfo());
h.CheckValue(input, nameof(input));
// For each topic, provide information about the (item, score) pairs.
public readonly Dictionary<int, List<Tuple<int, float>>> ItemScoresPerTopic;

@Zruty0Zruty0Nov 20, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the int key in this dictionary? Is it a sequential integer? If yes, make it into ImmutableArray. If it's not a sequential integer, describe what it is, and make it into an IReadOnlyDictionary #Resolved

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

made it ImmutableArray since its a sequential integer


In reply to: 234857025 [](ancestors = 234857025)

@Zruty0Zruty0 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@Zruty0

Copy link
Copy Markdown
Contributor

Approval conditional on fixing all the remaining open comments :)


/// <summary>
/// Initializes a new instance of <see cref="LatentDirichletAllocationEstimator"/>.
/// </summary>

@Ivanidzo4kaIvanidzo4kaNov 20, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use summary form method above.
It should be user friendly. #Resolved

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


In reply to: 235162180 [](ancestors = 235162180)

}

ResetRandomGenerator = item.ResetRandomGenerator ?? args.ResetRandomGenerator;
internal ColumnInfo(Column item, Arguments args)

@Ivanidzo4kaIvanidzo4kaNov 20, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

internal ColumnInfo(Column item, Arguments args) [](start = 12, length = 48)

you can just call constructor above, and that way you don't need to duplicate code.
internal ColumnInfo(Column item, Arguments args): this( item.Source, item.Name, args.NumTopic, ....)
#Resolved

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


In reply to: 235162967 [](ancestors = 235162967)

}
}

public const string LoaderSignature = "LdaTransform";

@Ivanidzo4kaIvanidzo4kaNov 20, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public [](start = 8, length = 6)

internal #Resolved

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


In reply to: 235163681 [](ancestors = 235163681)


// The following call fails because of the following issue
// https://github.com/dotnet/machinelearning/issues/969
// In this test it manifests because of the WordBagEstimator in the estimator chain

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would happen if you uncomment this?
I've recently convert WordBag to estimator so it should work properly.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I uncomment this, I get an error

Schema mismatch for input column 'text': expected Text, got R4 Parameter name: inputSchema

The WordBagWorkout test still comments out the TestEstimatorCore (line #186 above) .


In reply to: 235166598 [](ancestors = 235166598)

@Ivanidzo4kaIvanidzo4ka left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@shauheen
shauheen merged commit 1a9e7aa into dotnet:masterNov 20, 2018
@abgoswam
abgoswam deleted the abgoswam/LDA_conversion branch January 13, 2019 18:12
@ghostghost locked as resolved and limited conversation to collaborators Mar 27, 2022
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants

@abgoswam@artidoro@Zruty0@shauheen@Ivanidzo4ka@wschin@sfilipi
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length \u003e 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Convert LdaTransform to IEstimator/ITransformer API - #1410

Merged
shauheen merged 38 commits into
dotnet:masterfrom
abgoswam:abgoswam/LDA_conversion
Nov 20, 2018
Merged

Convert LdaTransform to IEstimator/ITransformer API#1410
shauheen merged 38 commits into
dotnet:masterfrom
abgoswam:abgoswam/LDA_conversion

Conversation

@abgoswam

@abgoswamabgoswam commented Oct 27, 2018

Copy link
Copy Markdown
Member

This PR converts LdaTransform to the IEstimator/ITransformer API paradigm (a work item related to #754)

  • LdaTransform is now subclass of OneToOneTransformerBase
  • Deleted the previous wrapped version.
  • Added pigsty extensions
  • Added onFit delegate to return LdaState info to user

Created separate issue #1411 for providing a convenient way of providing LDA topic summary info to the user

using Microsoft.ML.Runtime.Internal.Utilities;
using Microsoft.ML.Runtime.Model;
using Microsoft.ML.Runtime.TextAnalytics;
using Microsoft.ML.Core.Data;

@Ivanidzo4kaIvanidzo4kaOct 29, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ctrl+R+G (aka sort using) #Closed


// The type T asociated with the delegate will be the actual value type once #863 goes in.
// However, until such time as #863 goes in, it would be too awkward to attempt to extract the metadata.
// For now construct the useless object then pass it into the delegate.

@Ivanidzo4kaIvanidzo4kaOct 31, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this comment doesn't seems right. #Resolved

[assembly: LoadableClass(typeof(IRowMapper), typeof(LdaTransform), null, typeof(SignatureLoadRowMapper),
"Latent Dirichlet Allocation Transform", LdaTransform.LoaderSignature)]

namespace Microsoft.ML.Runtime.TextAnalytics

@Ivanidzo4kaIvanidzo4kaOct 31, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Runtime [](start = 23, length = 7)

Can you merge with master, I'm sure Senja changed this namespace to something better. #Resolved

try
{
var lda = new LdaTransform(Env, args, srcView);
var lda = LdaTransform.Create(Env, args, srcView);

@Ivanidzo4kaIvanidzo4kaOct 31, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LdaTransform [](start = 26, length = 12)

Can you switch to estimator call?
Basically var lda = LdaEstimator(env, cols).Fit(srcView).Transform(scrView); #Resolved

/// <param name="numSummaryTermPerTopic">The number of words to summarize the topic</param>
/// <param name="numBurninIterations">The number of burn-in iterations</param>
/// <param name="resetRandomGenerator">Reset the random number generator for each document</param>
/// <param name="onFit">Called upon fitting with the learnt enumeration on the dataset.</param>

@Ivanidzo4kaIvanidzo4kaOct 31, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sprinkle it with dots at the end of sentence. #Resolved

Contracts.Assert(0 <= iinfo && iinfo < _parent.ColumnPairs.Length);
disposer = null;

var test = TestType(_srcTypes[iinfo]);

@abgoswamabgoswamNov 5, 2018

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TestType [](start = 27, length = 8)

@ivan. Should we put this check here v/s putting it in the Mapper constructor ? Does it make a difference ? #Closed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It make difference at what point it will fail. I would prefer to test types in constructor.


In reply to: 230899143 [](ancestors = 230899143)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer not to have TestType idiom please


In reply to: 232105072 [](ancestors = 232105072,230899143)

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if column type in incorrect we now throw ExceptSchemaMismatch


In reply to: 232437787 [](ancestors = 232437787,232105072,230899143)

private struct Config
{
public readonly int NumTopic;
public readonly Single AlphaSum;

@wschinwschinNov 6, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
publicreadonlySingleAlphaSum;
publicreadonlyfloatAlphaSum;
``` #Resolved

{
public readonly int NumTopic;
public readonly Single AlphaSum;
public readonly Single Beta;

@wschinwschinNov 6, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
publicreadonlySingleBeta;
publicreadonlyfloatBeta;
``` #Resolved

using System.Text;
using Xunit;
using Xunit.Abstractions;
using static Microsoft.ML.Transforms.Text.LdaTransform;

@artidoroartidoroNov 6, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sort the usings. #Resolved

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Control+R Control+G (remove and sort Using) gives this order itself


In reply to: 231324047 [](ancestors = 231324047)

}

/// <include file='doc.xml' path='doc/members/member[@name="LightLDA"]/*' />
/// <param name="input">The column to apply to.</param>

@wschinwschinNov 6, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you describe what this transform is doing briefly? #Resolved

/// <param name="onFit">Called upon fitting with the learnt enumeration on the dataset.</param>
public static Vector<float> ToLdaTopicVector(this Vector<float> input,
int numTopic = LdaEstimator.Defaults.NumTopic,
Single alphaSum = LdaEstimator.Defaults.AlphaSum,

@wschinwschinNov 6, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
SinglealphaSum=LdaEstimator.Defaults.AlphaSum,
floatalphaSum=LdaEstimator.Defaults.AlphaSum,
``` #Resolved

public static Vector<float> ToLdaTopicVector(this Vector<float> input,
int numTopic = LdaEstimator.Defaults.NumTopic,
Single alphaSum = LdaEstimator.Defaults.AlphaSum,
Single beta = LdaEstimator.Defaults.Beta,

@wschinwschinNov 6, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Singlebeta=LdaEstimator.Defaults.Beta,
floatbeta=LdaEstimator.Defaults.Beta,
``` #Resolved

@artidoro

artidoro commented Nov 7, 2018

Copy link
Copy Markdown
Contributor

Could you add mlcontext extensions?
You can follow this PR as an example: #1524. The whitening PR also does that. #Resolved

}

private sealed class ColInfoEx
public sealed class ColumnInfo

@artidoroartidoroNov 7, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not combine this with transformInfo? You can just add this public constructor and change the name to columnInfo, while keeping the other methods internal/private. #Resolved

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any reason why you can't delete TransformInfo class and use ColumnInfo instead.


In reply to: 231632966 [](ancestors = 231632966)

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


In reply to: 232104746 [](ancestors = 232104746,231632966)

getSrc(ref src);
lda.Output(in src, ref dst, numBurninIter, reset);
};
return new LdaTransform(_host, input, _columns);

@artidoroartidoroNov 7, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

=> #Closed

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


In reply to: 231635318 [](ancestors = 231635318)

}
using (var ch = Host.Start("Train"))
{
Train(ch, input, _ldas);

@artidoroartidoroNov 7, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Train [](start = 16, length = 5)

Pete suggested that we make training a private static method in the transform, and that we have a constructor for the transform that will accept the trained parameters as an input.

This should make it easier to allow initialization of the transform using parameters coming from an external training routine. It is not something that we are exposing now, however.

This allows the transform to only keep the fields storing trained parameters. For example _types should no longer be needed as a field in the transform. #Closed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have implemented something like this for whitening.


In reply to: 231639657 [](ancestors = 231639657)

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed. thanks for giving the context about this approach.


In reply to: 231640188 [](ancestors = 231640188,231639657)


NumThread = item.NumThreads ?? args.NumThreads ?? 0;
ectx.CheckUserArg(NumThread >= 0, nameof(item.NumThreads), "Must be positive or zero.");
public sealed class LdaState : IDisposable

@artidoroartidoroNov 7, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public [](start = 8, length = 6)

Can this be made internal/private? #Closed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like some 'LDA guts' and should under no circumstances be exposed to the user.


In reply to: 231641222 [](ancestors = 231641222)

@abgoswamabgoswamNov 11, 2018

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made this internal. Instead added a class LdaTopicSummary to provide topic summary information back to users (when needed)


In reply to: 232437742 [](ancestors = 232437742,231641222)

@abgoswam

abgoswam commented Nov 15, 2018

Copy link
Copy Markdown
MemberAuthor

@Zruty0 I have addressed your PR comments. Could you kindly take a look ? #Resolved

@shauheen

shauheen commented Nov 19, 2018

Copy link
Copy Markdown
Contributor

ping @Zruty0 #Resolved

using System;
using System.Collections.Generic;

namespace Microsoft.ML.Transforms.Text

@Ivanidzo4kaIvanidzo4kaNov 19, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Microsoft.ML.Transforms.Text [](start = 10, length = 28)

Pete will ask you to put static extensions into Microsoft.ML.StaticPipe; #Closed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I sure will


In reply to: 234771139 [](ancestors = 234771139)

ectx.CheckUserArg(NumBurninIter >= 0, nameof(item.NumBurninIterations), "Must be non-negative.");
Contracts.CheckValue(input, nameof(input));
Contracts.CheckValueOrNull(output);
Contracts.CheckUserArg(numTopic > 0, nameof(numTopic), "Must be positive.");

@Zruty0Zruty0Nov 20, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CheckUserArg [](start = 26, length = 12)

Unless parsing command line, use CheckParam instead of CheckUserArg #Resolved

ctx.CheckAtModel(GetVersionInfo());
h.CheckValue(input, nameof(input));
// For each topic, provide information about the (item, score) pairs.
public readonly Dictionary<int, List<Tuple<int, float>>> ItemScoresPerTopic;

@Zruty0Zruty0Nov 20, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

List<Tuple<int, float> [](start = 44, length = 22)

Tuple<int, float> -> (int Item, float Score) (use named tuple instead of tuples)
List -> `ImmutableArray
#Resolved

ctx.CheckAtModel(GetVersionInfo());
h.CheckValue(input, nameof(input));
// For each topic, provide information about the (item, score) pairs.
public readonly Dictionary<int, List<Tuple<int, float>>> ItemScoresPerTopic;

@Zruty0Zruty0Nov 20, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the int key in this dictionary? Is it a sequential integer? If yes, make it into ImmutableArray. If it's not a sequential integer, describe what it is, and make it into an IReadOnlyDictionary #Resolved

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

made it ImmutableArray since its a sequential integer


In reply to: 234857025 [](ancestors = 234857025)

@Zruty0Zruty0 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@Zruty0

Copy link
Copy Markdown
Contributor

Approval conditional on fixing all the remaining open comments :)


/// <summary>
/// Initializes a new instance of <see cref="LatentDirichletAllocationEstimator"/>.
/// </summary>

@Ivanidzo4kaIvanidzo4kaNov 20, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use summary form method above.
It should be user friendly. #Resolved

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


In reply to: 235162180 [](ancestors = 235162180)

}

ResetRandomGenerator = item.ResetRandomGenerator ?? args.ResetRandomGenerator;
internal ColumnInfo(Column item, Arguments args)

@Ivanidzo4kaIvanidzo4kaNov 20, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

internal ColumnInfo(Column item, Arguments args) [](start = 12, length = 48)

you can just call constructor above, and that way you don't need to duplicate code.
internal ColumnInfo(Column item, Arguments args): this( item.Source, item.Name, args.NumTopic, ....)
#Resolved

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


In reply to: 235162967 [](ancestors = 235162967)

}
}

public const string LoaderSignature = "LdaTransform";

@Ivanidzo4kaIvanidzo4kaNov 20, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public [](start = 8, length = 6)

internal #Resolved

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


In reply to: 235163681 [](ancestors = 235163681)


// The following call fails because of the following issue
// https://github.com/dotnet/machinelearning/issues/969
// In this test it manifests because of the WordBagEstimator in the estimator chain

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would happen if you uncomment this?
I've recently convert WordBag to estimator so it should work properly.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I uncomment this, I get an error

Schema mismatch for input column 'text': expected Text, got R4 Parameter name: inputSchema

The WordBagWorkout test still comments out the TestEstimatorCore (line #186 above) .


In reply to: 235166598 [](ancestors = 235166598)

@Ivanidzo4kaIvanidzo4ka left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@shauheen
shauheen merged commit 1a9e7aa into dotnet:masterNov 20, 2018
@abgoswam
abgoswam deleted the abgoswam/LDA_conversion branch January 13, 2019 18:12
@ghostghost locked as resolved and limited conversation to collaborators Mar 27, 2022
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants

@abgoswam@artidoro@Zruty0@shauheen@Ivanidzo4ka@wschin@sfilipi
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content

Convert LdaTransform to IEstimator/ITransformer API - #1410

Merged
shauheen merged 38 commits into
dotnet:masterfrom
abgoswam:abgoswam/LDA_conversion
Nov 20, 2018
Merged

Convert LdaTransform to IEstimator/ITransformer API#1410
shauheen merged 38 commits into
dotnet:masterfrom
abgoswam:abgoswam/LDA_conversion

Conversation

@abgoswam

@abgoswamabgoswam commented Oct 27, 2018

Copy link
Copy Markdown
Member

This PR converts LdaTransform to the IEstimator/ITransformer API paradigm (a work item related to #754)

  • LdaTransform is now subclass of OneToOneTransformerBase
  • Deleted the previous wrapped version.
  • Added pigsty extensions
  • Added onFit delegate to return LdaState info to user

Created separate issue #1411 for providing a convenient way of providing LDA topic summary info to the user

using Microsoft.ML.Runtime.Internal.Utilities;
using Microsoft.ML.Runtime.Model;
using Microsoft.ML.Runtime.TextAnalytics;
using Microsoft.ML.Core.Data;

@Ivanidzo4kaIvanidzo4kaOct 29, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ctrl+R+G (aka sort using) #Closed


// The type T asociated with the delegate will be the actual value type once #863 goes in.
// However, until such time as #863 goes in, it would be too awkward to attempt to extract the metadata.
// For now construct the useless object then pass it into the delegate.

@Ivanidzo4kaIvanidzo4kaOct 31, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this comment doesn't seems right. #Resolved

[assembly: LoadableClass(typeof(IRowMapper), typeof(LdaTransform), null, typeof(SignatureLoadRowMapper),
"Latent Dirichlet Allocation Transform", LdaTransform.LoaderSignature)]

namespace Microsoft.ML.Runtime.TextAnalytics

@Ivanidzo4kaIvanidzo4kaOct 31, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Runtime [](start = 23, length = 7)

Can you merge with master, I'm sure Senja changed this namespace to something better. #Resolved

try
{
var lda = new LdaTransform(Env, args, srcView);
var lda = LdaTransform.Create(Env, args, srcView);

@Ivanidzo4kaIvanidzo4kaOct 31, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LdaTransform [](start = 26, length = 12)

Can you switch to estimator call?
Basically var lda = LdaEstimator(env, cols).Fit(srcView).Transform(scrView); #Resolved

/// <param name="numSummaryTermPerTopic">The number of words to summarize the topic</param>
/// <param name="numBurninIterations">The number of burn-in iterations</param>
/// <param name="resetRandomGenerator">Reset the random number generator for each document</param>
/// <param name="onFit">Called upon fitting with the learnt enumeration on the dataset.</param>

@Ivanidzo4kaIvanidzo4kaOct 31, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sprinkle it with dots at the end of sentence. #Resolved

Contracts.Assert(0 <= iinfo && iinfo < _parent.ColumnPairs.Length);
disposer = null;

var test = TestType(_srcTypes[iinfo]);

@abgoswamabgoswamNov 5, 2018

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TestType [](start = 27, length = 8)

@ivan. Should we put this check here v/s putting it in the Mapper constructor ? Does it make a difference ? #Closed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It make difference at what point it will fail. I would prefer to test types in constructor.


In reply to: 230899143 [](ancestors = 230899143)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer not to have TestType idiom please


In reply to: 232105072 [](ancestors = 232105072,230899143)

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if column type in incorrect we now throw ExceptSchemaMismatch


In reply to: 232437787 [](ancestors = 232437787,232105072,230899143)

private struct Config
{
public readonly int NumTopic;
public readonly Single AlphaSum;

@wschinwschinNov 6, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
publicreadonlySingleAlphaSum;
publicreadonlyfloatAlphaSum;
``` #Resolved

{
public readonly int NumTopic;
public readonly Single AlphaSum;
public readonly Single Beta;

@wschinwschinNov 6, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
publicreadonlySingleBeta;
publicreadonlyfloatBeta;
``` #Resolved

using System.Text;
using Xunit;
using Xunit.Abstractions;
using static Microsoft.ML.Transforms.Text.LdaTransform;

@artidoroartidoroNov 6, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sort the usings. #Resolved

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Control+R Control+G (remove and sort Using) gives this order itself


In reply to: 231324047 [](ancestors = 231324047)

}

/// <include file='doc.xml' path='doc/members/member[@name="LightLDA"]/*' />
/// <param name="input">The column to apply to.</param>

@wschinwschinNov 6, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you describe what this transform is doing briefly? #Resolved

/// <param name="onFit">Called upon fitting with the learnt enumeration on the dataset.</param>
public static Vector<float> ToLdaTopicVector(this Vector<float> input,
int numTopic = LdaEstimator.Defaults.NumTopic,
Single alphaSum = LdaEstimator.Defaults.AlphaSum,

@wschinwschinNov 6, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
SinglealphaSum=LdaEstimator.Defaults.AlphaSum,
floatalphaSum=LdaEstimator.Defaults.AlphaSum,
``` #Resolved

public static Vector<float> ToLdaTopicVector(this Vector<float> input,
int numTopic = LdaEstimator.Defaults.NumTopic,
Single alphaSum = LdaEstimator.Defaults.AlphaSum,
Single beta = LdaEstimator.Defaults.Beta,

@wschinwschinNov 6, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Singlebeta=LdaEstimator.Defaults.Beta,
floatbeta=LdaEstimator.Defaults.Beta,
``` #Resolved

@artidoro

artidoro commented Nov 7, 2018

Copy link
Copy Markdown
Contributor

Could you add mlcontext extensions?
You can follow this PR as an example: #1524. The whitening PR also does that. #Resolved

}

private sealed class ColInfoEx
public sealed class ColumnInfo

@artidoroartidoroNov 7, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not combine this with transformInfo? You can just add this public constructor and change the name to columnInfo, while keeping the other methods internal/private. #Resolved

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any reason why you can't delete TransformInfo class and use ColumnInfo instead.


In reply to: 231632966 [](ancestors = 231632966)

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


In reply to: 232104746 [](ancestors = 232104746,231632966)

getSrc(ref src);
lda.Output(in src, ref dst, numBurninIter, reset);
};
return new LdaTransform(_host, input, _columns);

@artidoroartidoroNov 7, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

=> #Closed

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


In reply to: 231635318 [](ancestors = 231635318)

}
using (var ch = Host.Start("Train"))
{
Train(ch, input, _ldas);

@artidoroartidoroNov 7, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Train [](start = 16, length = 5)

Pete suggested that we make training a private static method in the transform, and that we have a constructor for the transform that will accept the trained parameters as an input.

This should make it easier to allow initialization of the transform using parameters coming from an external training routine. It is not something that we are exposing now, however.

This allows the transform to only keep the fields storing trained parameters. For example _types should no longer be needed as a field in the transform. #Closed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have implemented something like this for whitening.


In reply to: 231639657 [](ancestors = 231639657)

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed. thanks for giving the context about this approach.


In reply to: 231640188 [](ancestors = 231640188,231639657)


NumThread = item.NumThreads ?? args.NumThreads ?? 0;
ectx.CheckUserArg(NumThread >= 0, nameof(item.NumThreads), "Must be positive or zero.");
public sealed class LdaState : IDisposable

@artidoroartidoroNov 7, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public [](start = 8, length = 6)

Can this be made internal/private? #Closed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like some 'LDA guts' and should under no circumstances be exposed to the user.


In reply to: 231641222 [](ancestors = 231641222)

@abgoswamabgoswamNov 11, 2018

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made this internal. Instead added a class LdaTopicSummary to provide topic summary information back to users (when needed)


In reply to: 232437742 [](ancestors = 232437742,231641222)

@abgoswam

abgoswam commented Nov 15, 2018

Copy link
Copy Markdown
MemberAuthor

@Zruty0 I have addressed your PR comments. Could you kindly take a look ? #Resolved

@shauheen

shauheen commented Nov 19, 2018

Copy link
Copy Markdown
Contributor

ping @Zruty0 #Resolved

using System;
using System.Collections.Generic;

namespace Microsoft.ML.Transforms.Text

@Ivanidzo4kaIvanidzo4kaNov 19, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Microsoft.ML.Transforms.Text [](start = 10, length = 28)

Pete will ask you to put static extensions into Microsoft.ML.StaticPipe; #Closed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I sure will


In reply to: 234771139 [](ancestors = 234771139)

ectx.CheckUserArg(NumBurninIter >= 0, nameof(item.NumBurninIterations), "Must be non-negative.");
Contracts.CheckValue(input, nameof(input));
Contracts.CheckValueOrNull(output);
Contracts.CheckUserArg(numTopic > 0, nameof(numTopic), "Must be positive.");

@Zruty0Zruty0Nov 20, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CheckUserArg [](start = 26, length = 12)

Unless parsing command line, use CheckParam instead of CheckUserArg #Resolved

ctx.CheckAtModel(GetVersionInfo());
h.CheckValue(input, nameof(input));
// For each topic, provide information about the (item, score) pairs.
public readonly Dictionary<int, List<Tuple<int, float>>> ItemScoresPerTopic;

@Zruty0Zruty0Nov 20, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

List<Tuple<int, float> [](start = 44, length = 22)

Tuple<int, float> -> (int Item, float Score) (use named tuple instead of tuples)
List -> `ImmutableArray
#Resolved

ctx.CheckAtModel(GetVersionInfo());
h.CheckValue(input, nameof(input));
// For each topic, provide information about the (item, score) pairs.
public readonly Dictionary<int, List<Tuple<int, float>>> ItemScoresPerTopic;

@Zruty0Zruty0Nov 20, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the int key in this dictionary? Is it a sequential integer? If yes, make it into ImmutableArray. If it's not a sequential integer, describe what it is, and make it into an IReadOnlyDictionary #Resolved

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

made it ImmutableArray since its a sequential integer


In reply to: 234857025 [](ancestors = 234857025)

@Zruty0Zruty0 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@Zruty0

Copy link
Copy Markdown
Contributor

Approval conditional on fixing all the remaining open comments :)


/// <summary>
/// Initializes a new instance of <see cref="LatentDirichletAllocationEstimator"/>.
/// </summary>

@Ivanidzo4kaIvanidzo4kaNov 20, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use summary form method above.
It should be user friendly. #Resolved

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


In reply to: 235162180 [](ancestors = 235162180)

}

ResetRandomGenerator = item.ResetRandomGenerator ?? args.ResetRandomGenerator;
internal ColumnInfo(Column item, Arguments args)

@Ivanidzo4kaIvanidzo4kaNov 20, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

internal ColumnInfo(Column item, Arguments args) [](start = 12, length = 48)

you can just call constructor above, and that way you don't need to duplicate code.
internal ColumnInfo(Column item, Arguments args): this( item.Source, item.Name, args.NumTopic, ....)
#Resolved

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


In reply to: 235162967 [](ancestors = 235162967)

}
}

public const string LoaderSignature = "LdaTransform";

@Ivanidzo4kaIvanidzo4kaNov 20, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public [](start = 8, length = 6)

internal #Resolved

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


In reply to: 235163681 [](ancestors = 235163681)


// The following call fails because of the following issue
// https://github.com/dotnet/machinelearning/issues/969
// In this test it manifests because of the WordBagEstimator in the estimator chain

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would happen if you uncomment this?
I've recently convert WordBag to estimator so it should work properly.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I uncomment this, I get an error

Schema mismatch for input column 'text': expected Text, got R4 Parameter name: inputSchema

The WordBagWorkout test still comments out the TestEstimatorCore (line #186 above) .


In reply to: 235166598 [](ancestors = 235166598)

@Ivanidzo4kaIvanidzo4ka left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@shauheen
shauheen merged commit 1a9e7aa into dotnet:masterNov 20, 2018
@abgoswam
abgoswam deleted the abgoswam/LDA_conversion branch January 13, 2019 18:12
@ghostghost locked as resolved and limited conversation to collaborators Mar 27, 2022
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants

@abgoswam@artidoro@Zruty0@shauheen@Ivanidzo4ka@wschin@sfilipi
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Convert LdaTransform to IEstimator/ITransformer API - #1410

Merged
shauheen merged 38 commits into
dotnet:masterfrom
abgoswam:abgoswam/LDA_conversion
Nov 20, 2018
Merged

Convert LdaTransform to IEstimator/ITransformer API#1410
shauheen merged 38 commits into
dotnet:masterfrom
abgoswam:abgoswam/LDA_conversion

Conversation

@abgoswam

@abgoswamabgoswam commented Oct 27, 2018

Copy link
Copy Markdown
Member

This PR converts LdaTransform to the IEstimator/ITransformer API paradigm (a work item related to #754)

  • LdaTransform is now subclass of OneToOneTransformerBase
  • Deleted the previous wrapped version.
  • Added pigsty extensions
  • Added onFit delegate to return LdaState info to user

Created separate issue #1411 for providing a convenient way of providing LDA topic summary info to the user

using Microsoft.ML.Runtime.Internal.Utilities;
using Microsoft.ML.Runtime.Model;
using Microsoft.ML.Runtime.TextAnalytics;
using Microsoft.ML.Core.Data;

@Ivanidzo4kaIvanidzo4kaOct 29, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ctrl+R+G (aka sort using) #Closed


// The type T asociated with the delegate will be the actual value type once #863 goes in.
// However, until such time as #863 goes in, it would be too awkward to attempt to extract the metadata.
// For now construct the useless object then pass it into the delegate.

@Ivanidzo4kaIvanidzo4kaOct 31, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this comment doesn't seems right. #Resolved

[assembly: LoadableClass(typeof(IRowMapper), typeof(LdaTransform), null, typeof(SignatureLoadRowMapper),
"Latent Dirichlet Allocation Transform", LdaTransform.LoaderSignature)]

namespace Microsoft.ML.Runtime.TextAnalytics

@Ivanidzo4kaIvanidzo4kaOct 31, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Runtime [](start = 23, length = 7)

Can you merge with master, I'm sure Senja changed this namespace to something better. #Resolved

try
{
var lda = new LdaTransform(Env, args, srcView);
var lda = LdaTransform.Create(Env, args, srcView);

@Ivanidzo4kaIvanidzo4kaOct 31, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LdaTransform [](start = 26, length = 12)

Can you switch to estimator call?
Basically var lda = LdaEstimator(env, cols).Fit(srcView).Transform(scrView); #Resolved

/// <param name="numSummaryTermPerTopic">The number of words to summarize the topic</param>
/// <param name="numBurninIterations">The number of burn-in iterations</param>
/// <param name="resetRandomGenerator">Reset the random number generator for each document</param>
/// <param name="onFit">Called upon fitting with the learnt enumeration on the dataset.</param>

@Ivanidzo4kaIvanidzo4kaOct 31, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sprinkle it with dots at the end of sentence. #Resolved

Contracts.Assert(0 <= iinfo && iinfo < _parent.ColumnPairs.Length);
disposer = null;

var test = TestType(_srcTypes[iinfo]);

@abgoswamabgoswamNov 5, 2018

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TestType [](start = 27, length = 8)

@ivan. Should we put this check here v/s putting it in the Mapper constructor ? Does it make a difference ? #Closed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It make difference at what point it will fail. I would prefer to test types in constructor.


In reply to: 230899143 [](ancestors = 230899143)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer not to have TestType idiom please


In reply to: 232105072 [](ancestors = 232105072,230899143)

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if column type in incorrect we now throw ExceptSchemaMismatch


In reply to: 232437787 [](ancestors = 232437787,232105072,230899143)

private struct Config
{
public readonly int NumTopic;
public readonly Single AlphaSum;

@wschinwschinNov 6, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
publicreadonlySingleAlphaSum;
publicreadonlyfloatAlphaSum;
``` #Resolved

{
public readonly int NumTopic;
public readonly Single AlphaSum;
public readonly Single Beta;

@wschinwschinNov 6, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
publicreadonlySingleBeta;
publicreadonlyfloatBeta;
``` #Resolved

using System.Text;
using Xunit;
using Xunit.Abstractions;
using static Microsoft.ML.Transforms.Text.LdaTransform;

@artidoroartidoroNov 6, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sort the usings. #Resolved

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Control+R Control+G (remove and sort Using) gives this order itself


In reply to: 231324047 [](ancestors = 231324047)

}

/// <include file='doc.xml' path='doc/members/member[@name="LightLDA"]/*' />
/// <param name="input">The column to apply to.</param>

@wschinwschinNov 6, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you describe what this transform is doing briefly? #Resolved

/// <param name="onFit">Called upon fitting with the learnt enumeration on the dataset.</param>
public static Vector<float> ToLdaTopicVector(this Vector<float> input,
int numTopic = LdaEstimator.Defaults.NumTopic,
Single alphaSum = LdaEstimator.Defaults.AlphaSum,

@wschinwschinNov 6, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
SinglealphaSum=LdaEstimator.Defaults.AlphaSum,
floatalphaSum=LdaEstimator.Defaults.AlphaSum,
``` #Resolved

public static Vector<float> ToLdaTopicVector(this Vector<float> input,
int numTopic = LdaEstimator.Defaults.NumTopic,
Single alphaSum = LdaEstimator.Defaults.AlphaSum,
Single beta = LdaEstimator.Defaults.Beta,

@wschinwschinNov 6, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Singlebeta=LdaEstimator.Defaults.Beta,
floatbeta=LdaEstimator.Defaults.Beta,
``` #Resolved

@artidoro

artidoro commented Nov 7, 2018

Copy link
Copy Markdown
Contributor

Could you add mlcontext extensions?
You can follow this PR as an example: #1524. The whitening PR also does that. #Resolved

}

private sealed class ColInfoEx
public sealed class ColumnInfo

@artidoroartidoroNov 7, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not combine this with transformInfo? You can just add this public constructor and change the name to columnInfo, while keeping the other methods internal/private. #Resolved

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any reason why you can't delete TransformInfo class and use ColumnInfo instead.


In reply to: 231632966 [](ancestors = 231632966)

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


In reply to: 232104746 [](ancestors = 232104746,231632966)

getSrc(ref src);
lda.Output(in src, ref dst, numBurninIter, reset);
};
return new LdaTransform(_host, input, _columns);

@artidoroartidoroNov 7, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

=> #Closed

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


In reply to: 231635318 [](ancestors = 231635318)

}
using (var ch = Host.Start("Train"))
{
Train(ch, input, _ldas);

@artidoroartidoroNov 7, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Train [](start = 16, length = 5)

Pete suggested that we make training a private static method in the transform, and that we have a constructor for the transform that will accept the trained parameters as an input.

This should make it easier to allow initialization of the transform using parameters coming from an external training routine. It is not something that we are exposing now, however.

This allows the transform to only keep the fields storing trained parameters. For example _types should no longer be needed as a field in the transform. #Closed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have implemented something like this for whitening.


In reply to: 231639657 [](ancestors = 231639657)

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed. thanks for giving the context about this approach.


In reply to: 231640188 [](ancestors = 231640188,231639657)


NumThread = item.NumThreads ?? args.NumThreads ?? 0;
ectx.CheckUserArg(NumThread >= 0, nameof(item.NumThreads), "Must be positive or zero.");
public sealed class LdaState : IDisposable

@artidoroartidoroNov 7, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public [](start = 8, length = 6)

Can this be made internal/private? #Closed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like some 'LDA guts' and should under no circumstances be exposed to the user.


In reply to: 231641222 [](ancestors = 231641222)

@abgoswamabgoswamNov 11, 2018

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made this internal. Instead added a class LdaTopicSummary to provide topic summary information back to users (when needed)


In reply to: 232437742 [](ancestors = 232437742,231641222)

@abgoswam

abgoswam commented Nov 15, 2018

Copy link
Copy Markdown
MemberAuthor

@Zruty0 I have addressed your PR comments. Could you kindly take a look ? #Resolved

@shauheen

shauheen commented Nov 19, 2018

Copy link
Copy Markdown
Contributor

ping @Zruty0 #Resolved

using System;
using System.Collections.Generic;

namespace Microsoft.ML.Transforms.Text

@Ivanidzo4kaIvanidzo4kaNov 19, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Microsoft.ML.Transforms.Text [](start = 10, length = 28)

Pete will ask you to put static extensions into Microsoft.ML.StaticPipe; #Closed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I sure will


In reply to: 234771139 [](ancestors = 234771139)

ectx.CheckUserArg(NumBurninIter >= 0, nameof(item.NumBurninIterations), "Must be non-negative.");
Contracts.CheckValue(input, nameof(input));
Contracts.CheckValueOrNull(output);
Contracts.CheckUserArg(numTopic > 0, nameof(numTopic), "Must be positive.");

@Zruty0Zruty0Nov 20, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CheckUserArg [](start = 26, length = 12)

Unless parsing command line, use CheckParam instead of CheckUserArg #Resolved

ctx.CheckAtModel(GetVersionInfo());
h.CheckValue(input, nameof(input));
// For each topic, provide information about the (item, score) pairs.
public readonly Dictionary<int, List<Tuple<int, float>>> ItemScoresPerTopic;

@Zruty0Zruty0Nov 20, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

List<Tuple<int, float> [](start = 44, length = 22)

Tuple<int, float> -> (int Item, float Score) (use named tuple instead of tuples)
List -> `ImmutableArray
#Resolved

ctx.CheckAtModel(GetVersionInfo());
h.CheckValue(input, nameof(input));
// For each topic, provide information about the (item, score) pairs.
public readonly Dictionary<int, List<Tuple<int, float>>> ItemScoresPerTopic;

@Zruty0Zruty0Nov 20, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the int key in this dictionary? Is it a sequential integer? If yes, make it into ImmutableArray. If it's not a sequential integer, describe what it is, and make it into an IReadOnlyDictionary #Resolved

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

made it ImmutableArray since its a sequential integer


In reply to: 234857025 [](ancestors = 234857025)

@Zruty0Zruty0 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@Zruty0

Copy link
Copy Markdown
Contributor

Approval conditional on fixing all the remaining open comments :)


/// <summary>
/// Initializes a new instance of <see cref="LatentDirichletAllocationEstimator"/>.
/// </summary>

@Ivanidzo4kaIvanidzo4kaNov 20, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use summary form method above.
It should be user friendly. #Resolved

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


In reply to: 235162180 [](ancestors = 235162180)

}

ResetRandomGenerator = item.ResetRandomGenerator ?? args.ResetRandomGenerator;
internal ColumnInfo(Column item, Arguments args)

@Ivanidzo4kaIvanidzo4kaNov 20, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

internal ColumnInfo(Column item, Arguments args) [](start = 12, length = 48)

you can just call constructor above, and that way you don't need to duplicate code.
internal ColumnInfo(Column item, Arguments args): this( item.Source, item.Name, args.NumTopic, ....)
#Resolved

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


In reply to: 235162967 [](ancestors = 235162967)

}
}

public const string LoaderSignature = "LdaTransform";

@Ivanidzo4kaIvanidzo4kaNov 20, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public [](start = 8, length = 6)

internal #Resolved

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


In reply to: 235163681 [](ancestors = 235163681)


// The following call fails because of the following issue
// https://github.com/dotnet/machinelearning/issues/969
// In this test it manifests because of the WordBagEstimator in the estimator chain

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would happen if you uncomment this?
I've recently convert WordBag to estimator so it should work properly.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I uncomment this, I get an error

Schema mismatch for input column 'text': expected Text, got R4 Parameter name: inputSchema

The WordBagWorkout test still comments out the TestEstimatorCore (line #186 above) .


In reply to: 235166598 [](ancestors = 235166598)

@Ivanidzo4kaIvanidzo4ka left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@shauheen
shauheen merged commit 1a9e7aa into dotnet:masterNov 20, 2018
@abgoswam
abgoswam deleted the abgoswam/LDA_conversion branch January 13, 2019 18:12
@ghostghost locked as resolved and limited conversation to collaborators Mar 27, 2022
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants

@abgoswam@artidoro@Zruty0@shauheen@Ivanidzo4ka@wschin@sfilipi
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Convert LdaTransform to IEstimator/ITransformer API - #1410

Merged
shauheen merged 38 commits into
dotnet:masterfrom
abgoswam:abgoswam/LDA_conversion
Nov 20, 2018
Merged

Convert LdaTransform to IEstimator/ITransformer API#1410
shauheen merged 38 commits into
dotnet:masterfrom
abgoswam:abgoswam/LDA_conversion

Conversation

@abgoswam

@abgoswamabgoswam commented Oct 27, 2018

Copy link
Copy Markdown
Member

This PR converts LdaTransform to the IEstimator/ITransformer API paradigm (a work item related to #754)

  • LdaTransform is now subclass of OneToOneTransformerBase
  • Deleted the previous wrapped version.
  • Added pigsty extensions
  • Added onFit delegate to return LdaState info to user

Created separate issue #1411 for providing a convenient way of providing LDA topic summary info to the user

using Microsoft.ML.Runtime.Internal.Utilities;
using Microsoft.ML.Runtime.Model;
using Microsoft.ML.Runtime.TextAnalytics;
using Microsoft.ML.Core.Data;

@Ivanidzo4kaIvanidzo4kaOct 29, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ctrl+R+G (aka sort using) #Closed


// The type T asociated with the delegate will be the actual value type once #863 goes in.
// However, until such time as #863 goes in, it would be too awkward to attempt to extract the metadata.
// For now construct the useless object then pass it into the delegate.

@Ivanidzo4kaIvanidzo4kaOct 31, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this comment doesn't seems right. #Resolved

[assembly: LoadableClass(typeof(IRowMapper), typeof(LdaTransform), null, typeof(SignatureLoadRowMapper),
"Latent Dirichlet Allocation Transform", LdaTransform.LoaderSignature)]

namespace Microsoft.ML.Runtime.TextAnalytics

@Ivanidzo4kaIvanidzo4kaOct 31, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Runtime [](start = 23, length = 7)

Can you merge with master, I'm sure Senja changed this namespace to something better. #Resolved

try
{
var lda = new LdaTransform(Env, args, srcView);
var lda = LdaTransform.Create(Env, args, srcView);

@Ivanidzo4kaIvanidzo4kaOct 31, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LdaTransform [](start = 26, length = 12)

Can you switch to estimator call?
Basically var lda = LdaEstimator(env, cols).Fit(srcView).Transform(scrView); #Resolved

/// <param name="numSummaryTermPerTopic">The number of words to summarize the topic</param>
/// <param name="numBurninIterations">The number of burn-in iterations</param>
/// <param name="resetRandomGenerator">Reset the random number generator for each document</param>
/// <param name="onFit">Called upon fitting with the learnt enumeration on the dataset.</param>

@Ivanidzo4kaIvanidzo4kaOct 31, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sprinkle it with dots at the end of sentence. #Resolved

Contracts.Assert(0 <= iinfo && iinfo < _parent.ColumnPairs.Length);
disposer = null;

var test = TestType(_srcTypes[iinfo]);

@abgoswamabgoswamNov 5, 2018

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TestType [](start = 27, length = 8)

@ivan. Should we put this check here v/s putting it in the Mapper constructor ? Does it make a difference ? #Closed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It make difference at what point it will fail. I would prefer to test types in constructor.


In reply to: 230899143 [](ancestors = 230899143)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer not to have TestType idiom please


In reply to: 232105072 [](ancestors = 232105072,230899143)

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if column type in incorrect we now throw ExceptSchemaMismatch


In reply to: 232437787 [](ancestors = 232437787,232105072,230899143)

private struct Config
{
public readonly int NumTopic;
public readonly Single AlphaSum;

@wschinwschinNov 6, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
publicreadonlySingleAlphaSum;
publicreadonlyfloatAlphaSum;
``` #Resolved

{
public readonly int NumTopic;
public readonly Single AlphaSum;
public readonly Single Beta;

@wschinwschinNov 6, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
publicreadonlySingleBeta;
publicreadonlyfloatBeta;
``` #Resolved

using System.Text;
using Xunit;
using Xunit.Abstractions;
using static Microsoft.ML.Transforms.Text.LdaTransform;

@artidoroartidoroNov 6, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sort the usings. #Resolved

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Control+R Control+G (remove and sort Using) gives this order itself


In reply to: 231324047 [](ancestors = 231324047)

}

/// <include file='doc.xml' path='doc/members/member[@name="LightLDA"]/*' />
/// <param name="input">The column to apply to.</param>

@wschinwschinNov 6, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you describe what this transform is doing briefly? #Resolved

/// <param name="onFit">Called upon fitting with the learnt enumeration on the dataset.</param>
public static Vector<float> ToLdaTopicVector(this Vector<float> input,
int numTopic = LdaEstimator.Defaults.NumTopic,
Single alphaSum = LdaEstimator.Defaults.AlphaSum,

@wschinwschinNov 6, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
SinglealphaSum=LdaEstimator.Defaults.AlphaSum,
floatalphaSum=LdaEstimator.Defaults.AlphaSum,
``` #Resolved

public static Vector<float> ToLdaTopicVector(this Vector<float> input,
int numTopic = LdaEstimator.Defaults.NumTopic,
Single alphaSum = LdaEstimator.Defaults.AlphaSum,
Single beta = LdaEstimator.Defaults.Beta,

@wschinwschinNov 6, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Singlebeta=LdaEstimator.Defaults.Beta,
floatbeta=LdaEstimator.Defaults.Beta,
``` #Resolved

@artidoro

artidoro commented Nov 7, 2018

Copy link
Copy Markdown
Contributor

Could you add mlcontext extensions?
You can follow this PR as an example: #1524. The whitening PR also does that. #Resolved

}

private sealed class ColInfoEx
public sealed class ColumnInfo

@artidoroartidoroNov 7, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not combine this with transformInfo? You can just add this public constructor and change the name to columnInfo, while keeping the other methods internal/private. #Resolved

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any reason why you can't delete TransformInfo class and use ColumnInfo instead.


In reply to: 231632966 [](ancestors = 231632966)

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


In reply to: 232104746 [](ancestors = 232104746,231632966)

getSrc(ref src);
lda.Output(in src, ref dst, numBurninIter, reset);
};
return new LdaTransform(_host, input, _columns);

@artidoroartidoroNov 7, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

=> #Closed

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


In reply to: 231635318 [](ancestors = 231635318)

}
using (var ch = Host.Start("Train"))
{
Train(ch, input, _ldas);

@artidoroartidoroNov 7, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Train [](start = 16, length = 5)

Pete suggested that we make training a private static method in the transform, and that we have a constructor for the transform that will accept the trained parameters as an input.

This should make it easier to allow initialization of the transform using parameters coming from an external training routine. It is not something that we are exposing now, however.

This allows the transform to only keep the fields storing trained parameters. For example _types should no longer be needed as a field in the transform. #Closed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have implemented something like this for whitening.


In reply to: 231639657 [](ancestors = 231639657)

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed. thanks for giving the context about this approach.


In reply to: 231640188 [](ancestors = 231640188,231639657)


NumThread = item.NumThreads ?? args.NumThreads ?? 0;
ectx.CheckUserArg(NumThread >= 0, nameof(item.NumThreads), "Must be positive or zero.");
public sealed class LdaState : IDisposable

@artidoroartidoroNov 7, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public [](start = 8, length = 6)

Can this be made internal/private? #Closed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like some 'LDA guts' and should under no circumstances be exposed to the user.


In reply to: 231641222 [](ancestors = 231641222)

@abgoswamabgoswamNov 11, 2018

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made this internal. Instead added a class LdaTopicSummary to provide topic summary information back to users (when needed)


In reply to: 232437742 [](ancestors = 232437742,231641222)

@abgoswam

abgoswam commented Nov 15, 2018

Copy link
Copy Markdown
MemberAuthor

@Zruty0 I have addressed your PR comments. Could you kindly take a look ? #Resolved

@shauheen

shauheen commented Nov 19, 2018

Copy link
Copy Markdown
Contributor

ping @Zruty0 #Resolved

using System;
using System.Collections.Generic;

namespace Microsoft.ML.Transforms.Text

@Ivanidzo4kaIvanidzo4kaNov 19, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Microsoft.ML.Transforms.Text [](start = 10, length = 28)

Pete will ask you to put static extensions into Microsoft.ML.StaticPipe; #Closed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I sure will


In reply to: 234771139 [](ancestors = 234771139)

ectx.CheckUserArg(NumBurninIter >= 0, nameof(item.NumBurninIterations), "Must be non-negative.");
Contracts.CheckValue(input, nameof(input));
Contracts.CheckValueOrNull(output);
Contracts.CheckUserArg(numTopic > 0, nameof(numTopic), "Must be positive.");

@Zruty0Zruty0Nov 20, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CheckUserArg [](start = 26, length = 12)

Unless parsing command line, use CheckParam instead of CheckUserArg #Resolved

ctx.CheckAtModel(GetVersionInfo());
h.CheckValue(input, nameof(input));
// For each topic, provide information about the (item, score) pairs.
public readonly Dictionary<int, List<Tuple<int, float>>> ItemScoresPerTopic;

@Zruty0Zruty0Nov 20, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

List<Tuple<int, float> [](start = 44, length = 22)

Tuple<int, float> -> (int Item, float Score) (use named tuple instead of tuples)
List -> `ImmutableArray
#Resolved

ctx.CheckAtModel(GetVersionInfo());
h.CheckValue(input, nameof(input));
// For each topic, provide information about the (item, score) pairs.
public readonly Dictionary<int, List<Tuple<int, float>>> ItemScoresPerTopic;

@Zruty0Zruty0Nov 20, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the int key in this dictionary? Is it a sequential integer? If yes, make it into ImmutableArray. If it's not a sequential integer, describe what it is, and make it into an IReadOnlyDictionary #Resolved

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

made it ImmutableArray since its a sequential integer


In reply to: 234857025 [](ancestors = 234857025)

@Zruty0Zruty0 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@Zruty0

Copy link
Copy Markdown
Contributor

Approval conditional on fixing all the remaining open comments :)


/// <summary>
/// Initializes a new instance of <see cref="LatentDirichletAllocationEstimator"/>.
/// </summary>

@Ivanidzo4kaIvanidzo4kaNov 20, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use summary form method above.
It should be user friendly. #Resolved

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


In reply to: 235162180 [](ancestors = 235162180)

}

ResetRandomGenerator = item.ResetRandomGenerator ?? args.ResetRandomGenerator;
internal ColumnInfo(Column item, Arguments args)

@Ivanidzo4kaIvanidzo4kaNov 20, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

internal ColumnInfo(Column item, Arguments args) [](start = 12, length = 48)

you can just call constructor above, and that way you don't need to duplicate code.
internal ColumnInfo(Column item, Arguments args): this( item.Source, item.Name, args.NumTopic, ....)
#Resolved

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


In reply to: 235162967 [](ancestors = 235162967)

}
}

public const string LoaderSignature = "LdaTransform";

@Ivanidzo4kaIvanidzo4kaNov 20, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public [](start = 8, length = 6)

internal #Resolved

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


In reply to: 235163681 [](ancestors = 235163681)


// The following call fails because of the following issue
// https://github.com/dotnet/machinelearning/issues/969
// In this test it manifests because of the WordBagEstimator in the estimator chain

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would happen if you uncomment this?
I've recently convert WordBag to estimator so it should work properly.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I uncomment this, I get an error

Schema mismatch for input column 'text': expected Text, got R4 Parameter name: inputSchema

The WordBagWorkout test still comments out the TestEstimatorCore (line #186 above) .


In reply to: 235166598 [](ancestors = 235166598)

@Ivanidzo4kaIvanidzo4ka left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@shauheen
shauheen merged commit 1a9e7aa into dotnet:masterNov 20, 2018
@abgoswam
abgoswam deleted the abgoswam/LDA_conversion branch January 13, 2019 18:12
@ghostghost locked as resolved and limited conversation to collaborators Mar 27, 2022
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants

@abgoswam@artidoro@Zruty0@shauheen@Ivanidzo4ka@wschin@sfilipi
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content

Convert LdaTransform to IEstimator/ITransformer API - #1410

Merged
shauheen merged 38 commits into
dotnet:masterfrom
abgoswam:abgoswam/LDA_conversion
Nov 20, 2018
Merged

Convert LdaTransform to IEstimator/ITransformer API#1410
shauheen merged 38 commits into
dotnet:masterfrom
abgoswam:abgoswam/LDA_conversion

Conversation

@abgoswam

@abgoswamabgoswam commented Oct 27, 2018

Copy link
Copy Markdown
Member

This PR converts LdaTransform to the IEstimator/ITransformer API paradigm (a work item related to #754)

  • LdaTransform is now subclass of OneToOneTransformerBase
  • Deleted the previous wrapped version.
  • Added pigsty extensions
  • Added onFit delegate to return LdaState info to user

Created separate issue #1411 for providing a convenient way of providing LDA topic summary info to the user

using Microsoft.ML.Runtime.Internal.Utilities;
using Microsoft.ML.Runtime.Model;
using Microsoft.ML.Runtime.TextAnalytics;
using Microsoft.ML.Core.Data;

@Ivanidzo4kaIvanidzo4kaOct 29, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ctrl+R+G (aka sort using) #Closed


// The type T asociated with the delegate will be the actual value type once #863 goes in.
// However, until such time as #863 goes in, it would be too awkward to attempt to extract the metadata.
// For now construct the useless object then pass it into the delegate.

@Ivanidzo4kaIvanidzo4kaOct 31, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this comment doesn't seems right. #Resolved

[assembly: LoadableClass(typeof(IRowMapper), typeof(LdaTransform), null, typeof(SignatureLoadRowMapper),
"Latent Dirichlet Allocation Transform", LdaTransform.LoaderSignature)]

namespace Microsoft.ML.Runtime.TextAnalytics

@Ivanidzo4kaIvanidzo4kaOct 31, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Runtime [](start = 23, length = 7)

Can you merge with master, I'm sure Senja changed this namespace to something better. #Resolved

try
{
var lda = new LdaTransform(Env, args, srcView);
var lda = LdaTransform.Create(Env, args, srcView);

@Ivanidzo4kaIvanidzo4kaOct 31, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LdaTransform [](start = 26, length = 12)

Can you switch to estimator call?
Basically var lda = LdaEstimator(env, cols).Fit(srcView).Transform(scrView); #Resolved

/// <param name="numSummaryTermPerTopic">The number of words to summarize the topic</param>
/// <param name="numBurninIterations">The number of burn-in iterations</param>
/// <param name="resetRandomGenerator">Reset the random number generator for each document</param>
/// <param name="onFit">Called upon fitting with the learnt enumeration on the dataset.</param>

@Ivanidzo4kaIvanidzo4kaOct 31, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sprinkle it with dots at the end of sentence. #Resolved

Contracts.Assert(0 <= iinfo && iinfo < _parent.ColumnPairs.Length);
disposer = null;

var test = TestType(_srcTypes[iinfo]);

@abgoswamabgoswamNov 5, 2018

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TestType [](start = 27, length = 8)

@ivan. Should we put this check here v/s putting it in the Mapper constructor ? Does it make a difference ? #Closed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It make difference at what point it will fail. I would prefer to test types in constructor.


In reply to: 230899143 [](ancestors = 230899143)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer not to have TestType idiom please


In reply to: 232105072 [](ancestors = 232105072,230899143)

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if column type in incorrect we now throw ExceptSchemaMismatch


In reply to: 232437787 [](ancestors = 232437787,232105072,230899143)

private struct Config
{
public readonly int NumTopic;
public readonly Single AlphaSum;

@wschinwschinNov 6, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
publicreadonlySingleAlphaSum;
publicreadonlyfloatAlphaSum;
``` #Resolved

{
public readonly int NumTopic;
public readonly Single AlphaSum;
public readonly Single Beta;

@wschinwschinNov 6, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
publicreadonlySingleBeta;
publicreadonlyfloatBeta;
``` #Resolved

using System.Text;
using Xunit;
using Xunit.Abstractions;
using static Microsoft.ML.Transforms.Text.LdaTransform;

@artidoroartidoroNov 6, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sort the usings. #Resolved

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Control+R Control+G (remove and sort Using) gives this order itself


In reply to: 231324047 [](ancestors = 231324047)

}

/// <include file='doc.xml' path='doc/members/member[@name="LightLDA"]/*' />
/// <param name="input">The column to apply to.</param>

@wschinwschinNov 6, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you describe what this transform is doing briefly? #Resolved

/// <param name="onFit">Called upon fitting with the learnt enumeration on the dataset.</param>
public static Vector<float> ToLdaTopicVector(this Vector<float> input,
int numTopic = LdaEstimator.Defaults.NumTopic,
Single alphaSum = LdaEstimator.Defaults.AlphaSum,

@wschinwschinNov 6, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
SinglealphaSum=LdaEstimator.Defaults.AlphaSum,
floatalphaSum=LdaEstimator.Defaults.AlphaSum,
``` #Resolved

public static Vector<float> ToLdaTopicVector(this Vector<float> input,
int numTopic = LdaEstimator.Defaults.NumTopic,
Single alphaSum = LdaEstimator.Defaults.AlphaSum,
Single beta = LdaEstimator.Defaults.Beta,

@wschinwschinNov 6, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Singlebeta=LdaEstimator.Defaults.Beta,
floatbeta=LdaEstimator.Defaults.Beta,
``` #Resolved

@artidoro

artidoro commented Nov 7, 2018

Copy link
Copy Markdown
Contributor

Could you add mlcontext extensions?
You can follow this PR as an example: #1524. The whitening PR also does that. #Resolved

}

private sealed class ColInfoEx
public sealed class ColumnInfo

@artidoroartidoroNov 7, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not combine this with transformInfo? You can just add this public constructor and change the name to columnInfo, while keeping the other methods internal/private. #Resolved

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any reason why you can't delete TransformInfo class and use ColumnInfo instead.


In reply to: 231632966 [](ancestors = 231632966)

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


In reply to: 232104746 [](ancestors = 232104746,231632966)

getSrc(ref src);
lda.Output(in src, ref dst, numBurninIter, reset);
};
return new LdaTransform(_host, input, _columns);

@artidoroartidoroNov 7, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

=> #Closed

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


In reply to: 231635318 [](ancestors = 231635318)

}
using (var ch = Host.Start("Train"))
{
Train(ch, input, _ldas);

@artidoroartidoroNov 7, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Train [](start = 16, length = 5)

Pete suggested that we make training a private static method in the transform, and that we have a constructor for the transform that will accept the trained parameters as an input.

This should make it easier to allow initialization of the transform using parameters coming from an external training routine. It is not something that we are exposing now, however.

This allows the transform to only keep the fields storing trained parameters. For example _types should no longer be needed as a field in the transform. #Closed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have implemented something like this for whitening.


In reply to: 231639657 [](ancestors = 231639657)

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed. thanks for giving the context about this approach.


In reply to: 231640188 [](ancestors = 231640188,231639657)


NumThread = item.NumThreads ?? args.NumThreads ?? 0;
ectx.CheckUserArg(NumThread >= 0, nameof(item.NumThreads), "Must be positive or zero.");
public sealed class LdaState : IDisposable

@artidoroartidoroNov 7, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public [](start = 8, length = 6)

Can this be made internal/private? #Closed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like some 'LDA guts' and should under no circumstances be exposed to the user.


In reply to: 231641222 [](ancestors = 231641222)

@abgoswamabgoswamNov 11, 2018

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made this internal. Instead added a class LdaTopicSummary to provide topic summary information back to users (when needed)


In reply to: 232437742 [](ancestors = 232437742,231641222)

@abgoswam

abgoswam commented Nov 15, 2018

Copy link
Copy Markdown
MemberAuthor

@Zruty0 I have addressed your PR comments. Could you kindly take a look ? #Resolved

@shauheen

shauheen commented Nov 19, 2018

Copy link
Copy Markdown
Contributor

ping @Zruty0 #Resolved

using System;
using System.Collections.Generic;

namespace Microsoft.ML.Transforms.Text

@Ivanidzo4kaIvanidzo4kaNov 19, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Microsoft.ML.Transforms.Text [](start = 10, length = 28)

Pete will ask you to put static extensions into Microsoft.ML.StaticPipe; #Closed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I sure will


In reply to: 234771139 [](ancestors = 234771139)

ectx.CheckUserArg(NumBurninIter >= 0, nameof(item.NumBurninIterations), "Must be non-negative.");
Contracts.CheckValue(input, nameof(input));
Contracts.CheckValueOrNull(output);
Contracts.CheckUserArg(numTopic > 0, nameof(numTopic), "Must be positive.");

@Zruty0Zruty0Nov 20, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CheckUserArg [](start = 26, length = 12)

Unless parsing command line, use CheckParam instead of CheckUserArg #Resolved

ctx.CheckAtModel(GetVersionInfo());
h.CheckValue(input, nameof(input));
// For each topic, provide information about the (item, score) pairs.
public readonly Dictionary<int, List<Tuple<int, float>>> ItemScoresPerTopic;

@Zruty0Zruty0Nov 20, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

List<Tuple<int, float> [](start = 44, length = 22)

Tuple<int, float> -> (int Item, float Score) (use named tuple instead of tuples)
List -> `ImmutableArray
#Resolved

ctx.CheckAtModel(GetVersionInfo());
h.CheckValue(input, nameof(input));
// For each topic, provide information about the (item, score) pairs.
public readonly Dictionary<int, List<Tuple<int, float>>> ItemScoresPerTopic;

@Zruty0Zruty0Nov 20, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the int key in this dictionary? Is it a sequential integer? If yes, make it into ImmutableArray. If it's not a sequential integer, describe what it is, and make it into an IReadOnlyDictionary #Resolved

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

made it ImmutableArray since its a sequential integer


In reply to: 234857025 [](ancestors = 234857025)

@Zruty0Zruty0 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@Zruty0

Copy link
Copy Markdown
Contributor

Approval conditional on fixing all the remaining open comments :)


/// <summary>
/// Initializes a new instance of <see cref="LatentDirichletAllocationEstimator"/>.
/// </summary>

@Ivanidzo4kaIvanidzo4kaNov 20, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use summary form method above.
It should be user friendly. #Resolved

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


In reply to: 235162180 [](ancestors = 235162180)

}

ResetRandomGenerator = item.ResetRandomGenerator ?? args.ResetRandomGenerator;
internal ColumnInfo(Column item, Arguments args)

@Ivanidzo4kaIvanidzo4kaNov 20, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

internal ColumnInfo(Column item, Arguments args) [](start = 12, length = 48)

you can just call constructor above, and that way you don't need to duplicate code.
internal ColumnInfo(Column item, Arguments args): this( item.Source, item.Name, args.NumTopic, ....)
#Resolved

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


In reply to: 235162967 [](ancestors = 235162967)

}
}

public const string LoaderSignature = "LdaTransform";

@Ivanidzo4kaIvanidzo4kaNov 20, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public [](start = 8, length = 6)

internal #Resolved

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


In reply to: 235163681 [](ancestors = 235163681)


// The following call fails because of the following issue
// https://github.com/dotnet/machinelearning/issues/969
// In this test it manifests because of the WordBagEstimator in the estimator chain

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would happen if you uncomment this?
I've recently convert WordBag to estimator so it should work properly.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I uncomment this, I get an error

Schema mismatch for input column 'text': expected Text, got R4 Parameter name: inputSchema

The WordBagWorkout test still comments out the TestEstimatorCore (line #186 above) .


In reply to: 235166598 [](ancestors = 235166598)

@Ivanidzo4kaIvanidzo4ka left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@shauheen
shauheen merged commit 1a9e7aa into dotnet:masterNov 20, 2018
@abgoswam
abgoswam deleted the abgoswam/LDA_conversion branch January 13, 2019 18:12
@ghostghost locked as resolved and limited conversation to collaborators Mar 27, 2022
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants

@abgoswam@artidoro@Zruty0@shauheen@Ivanidzo4ka@wschin@sfilipi