Documentation
¶
Index ¶
- Constants
- func BERTScore(candidates, refs [][]float64) (precision, recall, f1 float64)
- func DCG(relevance []int) float64
- func DotProduct(a, b []float64) float64
- func F1(precision, recall float64) float64
- func FBeta(precision, recall, beta float64) float64
- func IsClose(a, b float64) bool
- func IsZero(a float64) bool
- func L2Norm(a []float64) float64
- func LCS(a, b []string) int
- func NDCG(predicted []string, relevance map[string]int, k int) float64
- func Normalize(a []float64) []float64
- func Overlap(a, b []string) int
- func Precision(predicted []string, relevance map[string]int, k int) float64
- func ROUGE1(candidates, refs []string) (precision, recall, f1 float64)
- func ROUGEL(candidates, refs []string) (precision, recall, f1 float64)
- func ROUGELsum(candidates, refs [][]string) (precision, recall, f1 float64)
- func Recall(predicted []string, relevance map[string]int, k int) float64
Examples ¶
Constants ¶
View Source
const ( AbsTol = 1e-08 RelTol = 1e-05 )
Variables ¶
This section is empty.
Functions ¶
func BERTScore ¶
BERTScore returns the BERTScore between candidates and refs.
Example ¶
package main
import (
"fmt"
"github.com/itsubaki/reval"
)
func main() {
candidates := [][]float64{
{0.1, 0.2, 0.3},
{0.4, 0.5, 0.6},
}
refs := [][]float64{
{0.1, 0.2, 0.3},
{0.7, 0.8, 0.9},
}
precision, recall, f1 := reval.BERTScore(candidates, refs)
fmt.Printf("%.4f, %.4f, %.4f\n", precision, recall, f1)
}
Output: 0.8600, 0.7700, 0.8125
func DotProduct ¶
DotProduct returns the dot product of two vectors a and b.
func NDCG ¶
Example ¶
package main
import (
"fmt"
"github.com/itsubaki/reval"
)
func main() {
predicted := []string{"A", "B", "C", "D"}
relevance := map[string]int{
"A": 3,
"B": 2,
"C": 1,
"D": 0,
"E": 3,
}
s := reval.NDCG(predicted, relevance, 3)
fmt.Println("NDCG@3:", s)
}
Output: NDCG@3: 0.7271926019583822
func Precision ¶
Example ¶
package main
import (
"fmt"
"github.com/itsubaki/reval"
)
func main() {
predicted := []string{"A", "B", "C", "D"}
relevance := map[string]int{
"A": 3,
"B": 2,
"C": 0,
"D": 0,
"E": 3,
}
s := reval.Precision(predicted, relevance, 3)
fmt.Println("Precision@3:", s)
}
Output: Precision@3: 0.6666666666666666
func ROUGE1 ¶
ROUGE1 returns the ROUGE-1 score (unigram overlap)
Example ¶
package main
import (
"fmt"
"github.com/itsubaki/reval"
)
func main() {
candidates := []string{"the", "cat", "is", "sitting", "on", "the", "mat"}
refs := []string{"the", "cat", "sat", "on", "the", "mat"}
precision, recall, f1 := reval.ROUGE1(candidates, refs)
fmt.Printf("%.4f, %.4f, %.4f\n", precision, recall, f1)
}
Output: 0.7143, 0.8333, 0.7692
func ROUGEL ¶
ROUGEL returns the ROUGE-L score (Longest Common Subsequence)
Example ¶
package main
import (
"fmt"
"github.com/itsubaki/reval"
)
func main() {
candidates := []string{"the", "cat", "is", "sitting", "on", "the", "mat"}
refs := []string{"the", "cat", "sat", "on", "the", "mat"}
precision, recall, f1 := reval.ROUGEL(candidates, refs)
fmt.Printf("%.4f, %.4f, %.4f\n", precision, recall, f1)
}
Output: 0.7143, 0.8333, 0.7692
func ROUGELsum ¶
ROUGELsum returns the ROUGE-Lsum score for multiple sentences.
Example ¶
package main
import (
"fmt"
"github.com/itsubaki/reval"
)
func main() {
candidates := [][]string{
{"the", "cat", "is", "on", "the", "mat"},
{"it", "is", "cute"},
}
refs := [][]string{
{"the", "dog", "is", "on", "the", "mat"},
{"the", "animal", "is", "cute"},
{"the", "pet", "sleeps", "well"},
}
precision, recall, f1 := reval.ROUGELsum(candidates, refs)
fmt.Printf("%.4f, %.4f, %.4f\n", precision, recall, f1)
}
Output: 0.7778, 0.5000, 0.6087
func Recall ¶
Example ¶
package main
import (
"fmt"
"github.com/itsubaki/reval"
)
func main() {
predicted := []string{"A", "B", "C", "D"}
relevance := map[string]int{
"A": 3,
"B": 2,
"C": 1,
"D": 0,
"E": 3,
}
s := reval.Recall(predicted, relevance, 3)
fmt.Println("Recall@3:", s)
}
Output: Recall@3: 0.75
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.