Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add NameEntityRecognition and Q&A deep learning tasks. #6760

Merged
merged 16 commits into from
Jul 24, 2023

Conversation

michaelgsharp
Copy link
Member

This PR adds in 2 new deep learning scenarios, Name Entity Recognition and Q&A.

The main files to focus on are NerTrainer.cs and Roberta/QATrainer.cs. Most of the rest are either part of the deep learning model itself or internal implementations of things I had to copy over from runtime for them to work on netstandard.

@ghost ghost assigned michaelgsharp Jul 10, 2023
@michaelgsharp
Copy link
Member Author

Q&A currently has a runtime error I am working on resolving so the builds will fail for now. Getting the PR up so reviews can start while I finish debugging.


namespace Microsoft.ML.TorchSharp.NasBert.Models
{
internal sealed class ModelForPrediction : NasBertModel
Copy link
Contributor

Choose a reason for hiding this comment

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

NERInferenceModel?

Copy link
Member Author

Choose a reason for hiding this comment

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

This isn't for NER. Its for SentenceSimilarity and TextClassification. How about TextModel? TextModelForPrediction? Thoughts?

src/Microsoft.ML.TorchSharp/Utils/Range.cs Outdated Show resolved Hide resolved
src/Microsoft.ML.TorchSharp/Utils/Range.cs Outdated Show resolved Hide resolved
src/Microsoft.ML.TorchSharp/Utils/Range.cs Outdated Show resolved Hide resolved
src/Microsoft.ML.TorchSharp/Roberta/Models/RobertaModel.cs Outdated Show resolved Hide resolved

for (var i = 0; i < srcTokens.size(0); ++i)
{
var srcTokenArray = srcTokens[i].ToArray<int>();
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we could use the TensorAccessor exposed by the data method and avoid this array?

Copy link
Member Author

Choose a reason for hiding this comment

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

Looking into it it doesn't look like the TensorAccessor exposes enough to be able to do that. @NiklasGustafsson do you know if that is correct?

Copy link

@NiklasGustafsson NiklasGustafsson Jul 18, 2023

Choose a reason for hiding this comment

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

@michaelgsharp , I'm not sure which 'that' you're referring to. TensorAccessor implements IEnumerable.

Copy link
Member Author

Choose a reason for hiding this comment

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

I know the TensorAccessor has direct access to the underlying memory, but it doesn't expose the underlying memory directly, correct?

Copy link

@NiklasGustafsson NiklasGustafsson Jul 18, 2023

Choose a reason for hiding this comment

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

Indexing into the accessor will access the underlying native memory directly, both reading and writing, while ToArray() will make a copy.

        public T this[params long[] indices] {
            get {
                long index = 0;
                if (indices.Length == 1) {
                    index = indices[0];
                    validate(index);
                    unsafe {
                        T* ptr = (T*)_tensor_data_ptr;
                        return ptr[TranslateIndex(index, _tensor)];
                    }
                } else {
                    unsafe {
                        T* ptr = (T*)_tensor_data_ptr;
                        return ptr[TranslateIndex(indices, _tensor)];
                    }
                }
            }

@codecov
Copy link

codecov bot commented Jul 18, 2023

Codecov Report

Merging #6760 (407964d) into main (8858ab6) will increase coverage by 0.10%.
The diff coverage is 78.00%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6760      +/-   ##
==========================================
+ Coverage   68.89%   68.99%   +0.10%     
==========================================
  Files        1216     1237      +21     
  Lines      250915   252836    +1921     
  Branches    26259    26445     +186     
==========================================
+ Hits       172857   174450    +1593     
- Misses      71238    71454     +216     
- Partials     6820     6932     +112     
Flag Coverage Δ
Debug 68.99% <78.00%> (+0.10%) ⬆️
production 63.56% <80.16%> (+0.17%) ⬆️
test 88.83% <61.17%> (-0.08%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/Microsoft.ML.Tokenizers/Model/BPE.cs 70.68% <0.00%> (-0.87%) ⬇️
...Microsoft.ML.TorchSharp/NasBert/Models/BaseHead.cs 100.00% <ø> (+100.00%) ⬆️
...icrosoft.ML.TorchSharp/NasBert/Models/BaseModel.cs 60.00% <0.00%> (-6.67%) ⬇️
...oft.ML.TorchSharp/NasBert/Models/PredictionHead.cs 100.00% <ø> (ø)
src/Microsoft.ML.TorchSharp/Utils/MethodTable.cs 0.00% <0.00%> (ø)
src/Microsoft.ML.TorchSharp/Utils/Range.cs 31.57% <ø> (ø)
...soft.ML.TestFramework/DataPipe/TestDataPipeBase.cs 73.39% <0.00%> (-0.10%) ⬇️
test/Microsoft.ML.Tests/QATests.cs 40.50% <40.50%> (ø)
...osoft.ML.TorchSharp/NasBert/Models/NasBertModel.cs 86.11% <50.00%> (-3.48%) ⬇️
...oft.ML.TorchSharp/Roberta/Models/RobertaEncoder.cs 50.00% <50.00%> (ø)
... and 32 more

... and 36 files with indirect coverage changes

Copy link
Member

@ericstj ericstj left a comment

Choose a reason for hiding this comment

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

Thanks for resolving the feedback around GetSubArray - I'd still like for @LittleLittleCloud, @zewditu, or @JakeRadMSFT to give a pass

@michaelgsharp michaelgsharp merged commit 65c7ca9 into dotnet:main Jul 24, 2023
23 checks passed
@ghost ghost locked as resolved and limited conversation to collaborators Aug 24, 2023
Sign up for free to 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.

6 participants