-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add NameEntityRecognition and Q&A deep learning tasks. (#6760)
* NER * QA almost done, runtime error * QA finished * fixes from PR comments * fixed build * build fixes * perf changes * made disposable * fixed not disposing model * added some disposables to TensorFlow for memory * build testing * fixing build * added missing dispose * build fixes * build fixes * testing macos fix
- Loading branch information
1 parent
321158d
commit 65c7ca9
Showing
49 changed files
with
90,032 additions
and
383 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace Microsoft.ML.TorchSharp.NasBert | ||
{ | ||
internal enum BertModelType | ||
{ | ||
NasBert, | ||
Roberta | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/Microsoft.ML.TorchSharp/NasBert/Models/ModelPrediction.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using TorchSharp; | ||
|
||
namespace Microsoft.ML.TorchSharp.NasBert.Models | ||
{ | ||
internal sealed class ModelForPrediction : NasBertModel | ||
{ | ||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "MSML_PrivateFieldName:Private field name not in: _camelCase format", Justification = "Has to match TorchSharp model.")] | ||
private readonly PredictionHead PredictionHead; | ||
|
||
public override BaseHead GetHead() => PredictionHead; | ||
|
||
public ModelForPrediction(NasBertTrainer.NasBertOptions options, int padIndex, int symbolsCount, int numClasses) | ||
: base(options, padIndex, symbolsCount) | ||
{ | ||
PredictionHead = new PredictionHead( | ||
inputDim: Options.EncoderOutputDim, | ||
numClasses: numClasses, | ||
dropoutRate: Options.PoolerDropout); | ||
Initialize(); | ||
RegisterComponents(); | ||
} | ||
|
||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "MSML_GeneralName:This name should be PascalCased", Justification = "Need to match TorchSharp.")] | ||
public override torch.Tensor forward(torch.Tensor srcTokens, torch.Tensor tokenMask = null) | ||
{ | ||
using var disposeScope = torch.NewDisposeScope(); | ||
var x = ExtractFeatures(srcTokens); | ||
x = PredictionHead.call(x); | ||
return x.MoveToOuterDisposeScope(); | ||
} | ||
} | ||
} |
Oops, something went wrong.