rocketqa

package module
v0.0.0-...-e7bae2e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 3, 2023 License: MIT Imports: 3 Imported by: 2 modules, 3 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

rocketqa

Go Reference

Go Inference API for RocketQA.

Installation

  1. Install rocketqa

    $ go get -u github.com/go-aie/rocketqa
    
  2. Install Paddle Inference Go API

Documentation

Check out the documentation.

Testing and Benchmarking

Generate the inference models:

$ python3 cli/cli.py save zh_dureader_de_v2 --out-path=testdata/zh_dureader_de_v2
$ python3 cli/cli.py save zh_dureader_ce_v2 --out-path=testdata/zh_dureader_ce_v2

Run tests:

$ go test -v -race | grep -E 'go|Test'
=== RUN   TestCrossEncoder_Rank
--- PASS: TestCrossEncoder_Rank (0.69s)
=== RUN   TestDualEncoder_EncodeQuery
--- PASS: TestDualEncoder_EncodeQuery (0.97s)
=== RUN   TestDualEncoder_EncodePara
--- PASS: TestDualEncoder_EncodePara (0.77s)
ok  	github.com/go-aie/rocketqa	3.094s

Run benchmarks:

$ go test -bench=. -benchmem | grep -E 'go|Benchmark'
goos: darwin
goarch: arm64
pkg: github.com/go-aie/rocketqa
BenchmarkCrossEncoder_Rank/C-1-10      	      12	  95231254 ns/op	   21522 B/op	     557 allocs/op
BenchmarkCrossEncoder_Rank/C-2-10      	      24	  48904571 ns/op	   21224 B/op	     555 allocs/op
BenchmarkCrossEncoder_Rank/C-4-10      	      49	  25722997 ns/op	   21154 B/op	     554 allocs/op
BenchmarkCrossEncoder_Rank/C-8-10      	      87	  13775692 ns/op	   21003 B/op	     557 allocs/op
BenchmarkCrossEncoder_Rank/C-16-10     	      96	  12942040 ns/op	   20965 B/op	     555 allocs/op
BenchmarkCrossEncoder_Rank/C-32-10     	      96	  12374102 ns/op	   20869 B/op	     554 allocs/op
BenchmarkCrossEncoder_Rank/C-64-10     	      96	  12106736 ns/op	   20867 B/op	     554 allocs/op
BenchmarkDualEncoder_EncodeQuery/C-1-10         	      13	  87274330 ns/op	   91977 B/op	     463 allocs/op
BenchmarkDualEncoder_EncodeQuery/C-2-10         	      24	  46361825 ns/op	   92004 B/op	     464 allocs/op
BenchmarkDualEncoder_EncodeQuery/C-4-10         	      42	  24531967 ns/op	   92054 B/op	     465 allocs/op
BenchmarkDualEncoder_EncodeQuery/C-8-10         	      84	  13078837 ns/op	   91868 B/op	     463 allocs/op
BenchmarkDualEncoder_EncodeQuery/C-16-10        	      92	  12734853 ns/op	   91831 B/op	     460 allocs/op
BenchmarkDualEncoder_EncodeQuery/C-32-10        	      92	  12949048 ns/op	   91796 B/op	     462 allocs/op
BenchmarkDualEncoder_EncodeQuery/C-64-10        	      96	  12571607 ns/op	   91839 B/op	     462 allocs/op
BenchmarkDualEncoder_EncodePara/C-1-10          	      10	 102307329 ns/op	   97323 B/op	     600 allocs/op
BenchmarkDualEncoder_EncodePara/C-2-10          	      22	  52587379 ns/op	   97290 B/op	     599 allocs/op
BenchmarkDualEncoder_EncodePara/C-4-10          	      40	  27110265 ns/op	   97255 B/op	     597 allocs/op
BenchmarkDualEncoder_EncodePara/C-8-10          	      75	  15437987 ns/op	   97171 B/op	     597 allocs/op
BenchmarkDualEncoder_EncodePara/C-16-10         	      84	  14117255 ns/op	   97148 B/op	     597 allocs/op
BenchmarkDualEncoder_EncodePara/C-32-10         	      81	  14174034 ns/op	   97116 B/op	     596 allocs/op
BenchmarkDualEncoder_EncodePara/C-64-10         	      80	  14531767 ns/op	   97123 B/op	     597 allocs/op
ok  	github.com/go-aie/rocketqa	55.900s

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CrossEncoder

type CrossEncoder struct {
	// contains filtered or unexported fields
}

func NewCrossEncoder

func NewCrossEncoder(cfg *CrossEncoderConfig) (*CrossEncoder, error)

func (*CrossEncoder) Rank

func (ce *CrossEncoder) Rank(queries, paras, titles []string) ([]float32, error)

type CrossEncoderConfig

type CrossEncoderConfig struct {
	ModelPath, ParamsPath string
	VocabFile             string
	DoLowerCase           bool
	MaxSeqLength          int
	ForCN                 bool
	// The maximum number of predictors for concurrent inferences.
	// Defaults to the value of runtime.NumCPU.
	MaxConcurrency int
}

type DualEncoder

type DualEncoder struct {
	// contains filtered or unexported fields
}

func NewDualEncoder

func NewDualEncoder(cfg *DualEncoderConfig) (*DualEncoder, error)

func (*DualEncoder) EncodePara

func (de *DualEncoder) EncodePara(paras, titles []string) ([]Vector, error)

func (*DualEncoder) EncodeQuery

func (de *DualEncoder) EncodeQuery(queries []string) []Vector

type DualEncoderConfig

type DualEncoderConfig struct {
	ModelPath, ParamsPath string
	VocabFile             string
	DoLowerCase           bool
	QueryMaxSeqLength     int
	ParaMaxSeqLength      int
	ForCN                 bool
	// The maximum number of predictors for concurrent inferences.
	// Defaults to the value of runtime.NumCPU.
	MaxConcurrency int
}

type QPT

type QPT struct {
	Query string
	Para  string
	Title string
}

QPT is a structured type that represents a single parameter group.

type QPTs

type QPTs []QPT

QPTs is a helper type that makes it easy to construct parameters in a more structured way.

func (QPTs) P

func (qs QPTs) P() (paras []string)

P collects the values of the Para fields from all elements and return them as a slice.

func (QPTs) Q

func (qs QPTs) Q() (queries []string)

Q collects the values of the Query fields from all elements and return them as a slice.

func (QPTs) T

func (qs QPTs) T() (titles []string)

T collects the values of the Title fields from all elements and return them as a slice.

type Vector

type Vector []float32

func (Vector) Norm

func (v Vector) Norm() Vector

func (Vector) ToFloat64

func (v Vector) ToFloat64() []float64

Directories

Path Synopsis
examples
es module

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址