You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@opennlp.apache.org by GitBox <gi...@apache.org> on 2021/06/15 17:21:55 UTC
[GitHub] [opennlp] eihli opened a new pull request #392: OPENNLP-1330 Fix Parser's top "k" parses functionality from returning bottom "k" parses.
eihli opened a new pull request #392:
URL: https://github.com/apache/opennlp/pull/392
The default "top n parses" of 1 shows the most likely parse; one with a log prob of -2.9.
Passing in anything greater than 1 returns the least probable parses.
```
➜ bin git:(master) echo "Eric is testing." | ./opennlp Parser -k 1 ~/src/prhyme/resources/models/en-parser-chunking.bin
Loading Parser model ... done (2.515s)
0 -2.913239374955309 (TOP (S (NP (NNP Eric)) (VP (VBZ is)) (. testing.)))
Average: 41.7 sent/s
Total: 1 sent
Runtime: 0.024s
Execution time: 2.585 seconds
➜ bin git:(master) echo "Eric is testing." | ./opennlp Parser -k 2 ~/src/prhyme/resources/models/en-parser-chunking.bin
Loading Parser model ... done (2.578s)
0 -14.968552218782305 (TOP (S (NP (NNP Eric)) (SBAR (S (ADVP (VBZ is)) (VBG testing.)))))
1 -13.957766393572408 (TOP (S (SBAR (S (NP (NNP Eric)) (ADVP (VBZ is)))) (VBG testing.)))
Average: 95.2 sent/s
Total: 2 sent
Runtime: 0.021s
Execution time: 2.640 seconds
```
The fix is clear and simple. We should be taking from the first of the TreeSet rather than from the end.
```
else if (numParses == 1) {
return new Parse[] {completeParses.first()};
}
else {
List<Parse> topParses = new ArrayList<>(numParses);
while (!completeParses.isEmpty() && topParses.size() < numParses) {
Parse tp = completeParses.last(); //// <--- Change to .first()
completeParses.remove(tp);
topParses.add(tp);
//parses.remove(tp);
}
return topParses.toArray(new Parse[topParses.size()]);
}
```
After patch, results are what I expect.
```
➜ bin git:(master) ✗ echo "Eric is testing." | ./opennlp Parser -k 1 ~/src/prhyme/resources/models/en-parser-chunking.bin
Loading Parser model ... done (2.517s)
0 -2.913239374955309 (TOP (S (NP (NNP Eric)) (VP (VBZ is)) (. testing.)))
Average: 45.5 sent/s
Total: 1 sent
Runtime: 0.022s
Execution time: 2.580 seconds
➜ bin git:(master) ✗ echo "Eric is testing." | ./opennlp Parser -k 2 ~/src/prhyme/resources/models/en-parser-chunking.bin
Loading Parser model ... done (2.530s)
0 -2.913239374955309 (TOP (S (NP (NNP Eric)) (VP (VBZ is)) (. testing.)))
1 -3.1132674983145825 (TOP (S (NP (NNP Eric)) (VP (VBZ is) (NP (NN testing.)))))
Average: 90.9 sent/s
Total: 2 sent
Runtime: 0.022s
Execution time: 2.596 seconds
```
Thank you for contributing to Apache OpenNLP.
In order to streamline the review of the contribution we ask you
to ensure the following steps have been taken:
### For all changes:
- [x] Is there a JIRA ticket associated with this PR? Is it referenced
in the commit message?
- [x] Does your PR title start with OPENNLP-XXXX where XXXX is the JIRA number you are trying to resolve? Pay particular attention to the hyphen "-" character.
- [ ] Has your PR been rebased against the latest commit within the target branch (typically master)?
- [x] Is your initial contribution a single, squashed commit?
### For code changes:
- [ ] Have you ensured that the full suite of tests is executed via mvn clean install at the root opennlp folder?
- [ ] Have you written or updated unit tests to verify your changes?
- [-] If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under [ASF 2.0](http://www.apache.org/legal/resolved.html#category-a)?
- [-] If applicable, have you updated the LICENSE file, including the main LICENSE file in opennlp folder?
- [-] If applicable, have you updated the NOTICE file, including the main NOTICE file found in opennlp folder?
### For documentation related changes:
- [-] Have you ensured that format looks appropriate for the output in which it is rendered?
### Note:
Please ensure that once the PR is submitted, you check travis-ci for build issues and submit an update to your PR as soon as possible.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [opennlp] eihli commented on pull request #392: OPENNLP-1330 Fix Parser's top "k" parses functionality from returning bottom "k" parses.
Posted by GitBox <gi...@apache.org>.
eihli commented on pull request #392:
URL: https://github.com/apache/opennlp/pull/392#issuecomment-864057912
I think it's OK to merge this without adding a test. I couldn't find a location in the existing tests files that would be a good spot to add this. I'd love to dig in and figure out how to make a test case for this fit within an existing test file or create a new test. But that's a tall order (for me, given my newness to the codebase).
It would add significant delay for a small change that can be confidently reasoned about. The risk, in this case, is not that a code-related bug is introduced. The risk is that a reason/understanding-based bug is introduced. A test wouldn't fix faulty reasoning.
As for the reason this is `first` rather than `last`, https://docs.oracle.com/javase/7/docs/api/java/util/TreeSet.html.
```
A NavigableSet implementation based on a TreeMap.
The elements are ordered using their natural ordering,
or by a Comparator provided at set creation time,
depending on which constructor is used.
```
`completeParses` is defined as a TreeSet on line 187:
```
completeParses = new TreeSet<>();
```
And `Parse`s that are added to `completeParses` have a compareTo so they are ordered by their log probability.
```
public int compareTo(Parse p) {
return Double.compare(p.getProb(), this.getProb());
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [opennlp] jzonthemtn merged pull request #392: OPENNLP-1330 Fix Parser's top "k" parses functionality from returning bottom "k" parses.
Posted by GitBox <gi...@apache.org>.
jzonthemtn merged pull request #392:
URL: https://github.com/apache/opennlp/pull/392
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [opennlp] jzonthemtn commented on pull request #392: OPENNLP-1330 Fix Parser's top "k" parses functionality from returning bottom "k" parses.
Posted by GitBox <gi...@apache.org>.
jzonthemtn commented on pull request #392:
URL: https://github.com/apache/opennlp/pull/392#issuecomment-866796844
I wrote OPENNLP-1333 to capture the need for a unit test. Thanks again @eihli.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org