|
1 | 1 | package de.kherud.llama;
|
2 | 2 |
|
3 |
| -import java.io.*; |
4 |
| -import java.util.*; |
5 |
| -import java.util.regex.Pattern; |
| 3 | +import java.util.Map; |
6 | 4 |
|
7 |
| -import de.kherud.llama.args.LogFormat; |
8 | 5 | import org.junit.AfterClass;
|
9 | 6 | import org.junit.Assert;
|
10 | 7 | import org.junit.BeforeClass;
|
11 |
| -import org.junit.Ignore; |
12 | 8 | import org.junit.Test;
|
13 | 9 |
|
14 | 10 | public class RerankingModelTest {
|
@@ -41,7 +37,32 @@ public void testReRanking() {
|
41 | 37 | LlamaOutput llamaOutput = model.rerank(query, TEST_DOCUMENTS[0], TEST_DOCUMENTS[1], TEST_DOCUMENTS[2],
|
42 | 38 | TEST_DOCUMENTS[3]);
|
43 | 39 |
|
44 |
| - System.out.println(llamaOutput); |
| 40 | + Map<String, Float> rankedDocumentsMap = llamaOutput.probabilities; |
| 41 | + Assert.assertTrue(rankedDocumentsMap.size()==TEST_DOCUMENTS.length); |
| 42 | + |
| 43 | + // Finding the most and least relevant documents |
| 44 | + String mostRelevantDoc = null; |
| 45 | + String leastRelevantDoc = null; |
| 46 | + float maxScore = Float.MIN_VALUE; |
| 47 | + float minScore = Float.MAX_VALUE; |
| 48 | + |
| 49 | + for (Map.Entry<String, Float> entry : rankedDocumentsMap.entrySet()) { |
| 50 | + if (entry.getValue() > maxScore) { |
| 51 | + maxScore = entry.getValue(); |
| 52 | + mostRelevantDoc = entry.getKey(); |
| 53 | + } |
| 54 | + if (entry.getValue() < minScore) { |
| 55 | + minScore = entry.getValue(); |
| 56 | + leastRelevantDoc = entry.getKey(); |
| 57 | + } |
| 58 | + } |
| 59 | + |
| 60 | + // Assertions |
| 61 | + Assert.assertTrue(maxScore > minScore); |
| 62 | + Assert.assertEquals("Machine learning is a field of study in artificial intelligence concerned with the development and study of statistical algorithms that can learn from data and generalize to unseen data, and thus perform tasks without explicit instructions.", mostRelevantDoc); |
| 63 | + Assert.assertEquals("Paris, capitale de la France, est une grande ville européenne et un centre mondial de l'art, de la mode, de la gastronomie et de la culture. Son paysage urbain du XIXe siècle est traversé par de larges boulevards et la Seine.", leastRelevantDoc); |
| 64 | + |
| 65 | + |
45 | 66 | }
|
46 | 67 |
|
47 | 68 | }
|
0 commit comments