There's more...

For any given sentence, there are often more than one possible sequence of POS tags. The topKSequences method returns a list of possible sequences:

Sequence topSequences[] = posTaggerME.topKSequences(words);

For each sequence, we can list the each outcome along with its corresponding word. In the next set of statements, we iterate over each sequence and then, for each sequence, we use the getOutcomes method to return a list of tags. The inner for loop will display each sentence with their tags:

for (Sequence sequence : topSequences) {
List<String> outcomes = sequence.getOutcomes();
System.out.print("[");
for(int i=0; i<outcomes.size(); i++) {
System.out.print(words[i] + "/" + outcomes.get(i) + " ");
}
System.out.println("]");
}

When this code is executed, you will get the following output:

[When/WRB the/DT mouse/NN saw/VBD the/DT cat/NN it/PRP ran/VBD away./. ]
[When/WRB the/DT mouse/NN saw/VBD the/DT cat/NN it/PRP ran/VBD away./RB ]
[When/WRB the/DT mouse/NN saw/VBD the/DT cat/NN it/PRP ran/VBD away./VBG ]

Associated with each possible set of tags is a set of probabilities indicating the likelihood of the results being correct. The next code sequence is similar to the previous except we have used the getProbs method of the Sequence class to obtain the probabilities that are listed, along with the corresponding word and tag:

for (Sequence sequence : topSequences) {
List<String> outcomes = sequence.getOutcomes();
double probabilities[] = sequence.getProbs();
for (int i = 0; i < outcomes.size(); i++) {
System.out.printf("%s/%s/%5.3f ",words[i],
outcomes.get(i), probabilities[i]);
}
System.out.println();
}

When this code is executed, you will get the following output:

When/WRB/0.985 the/DT/0.976 mouse/NN/0.994 saw/VBD/0.993 the/DT/0.976 cat/NN/0.985 it/PRP/0.925 ran/VBD/0.992 away././0.358 
When/WRB/0.985 the/DT/0.976 mouse/NN/0.994 saw/VBD/0.993 the/DT/0.976 cat/NN/0.985 it/PRP/0.925 ran/VBD/0.992 away./RB/0.347
When/WRB/0.985 the/DT/0.976 mouse/NN/0.994 saw/VBD/0.993 the/DT/0.976 cat/NN/0.985 it/PRP/0.925 ran/VBD/0.992 away./VBG/0.094
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.16.111.9