Documentation ¶
Index ¶
- Constants
- Variables
- func BatchPredict(ctx context.Context, recSys Predictor, sampleKeys []Sample) (y tensor.Tensor, err error)
- func GetItemEmbeddingModelFromUb(ctx context.Context, iSeq ItemEmbedding) (mod model.Model, err error)
- func GetSampleVector(ctx context.Context, userFeatureCache *ccache.Cache, ...) (vec []float32, userFeatureWidth int, itemFeatureWidth int, err error)
- func StartHttpApi(predict Predictor, path string, addr string, efs *embed.FS) (err error)
- type BasicFeatureProvider
- type DashboardOverviewResult
- type FeatureOverview
- type Fitter
- type ItemEmbedding
- type ItemFeaturer
- type ItemOverView
- type ItemOverviewResult
- type ItemScore
- type PreRanker
- type PreTrainer
- type PredictAbstract
- type Predictor
- type RecApiRequest
- type RecApiResponse
- type RecSys
- type Sample
- type SampleInfo
- type Stage
- type Tensor
- type TrainSample
- type Trainer
- type UserBehavior
- type UserFeaturer
- type UserItemOverview
- type UserItemOverviewResult
Constants ¶
View Source
const ( SampleAssembler = 16 StageKey = "stage" ItemEmbDim = 16 ItemEmbWindow = 5 UserBehaviorLen = 10 )
Variables ¶
View Source
var ( //TODO: maybe a switch to control whether to reuse training cache when predict UserFeatureCache *ccache.Cache ItemFeatureCache *ccache.Cache UserBehaviorCache *ccache.Cache // DefaultUserFeature and DefaultItemFeature are backup if not nil //when user or item missing in database, use this to fill DefaultUserFeature []float32 DefaultItemFeature []float32 DebugUserId int DebugItemId int )
Functions ¶
func BatchPredict ¶
func GetSampleVector ¶ added in v0.2.0
func StartHttpApi ¶
StartHttpApi starts the http api for recommendation Query by:
curl --header "Content-Type: application/json" \ --request POST \ --data '{"userId":107,"itemIdList":[1,2,39]}' \ http://localhost:8080/api/v1/recommend
Types ¶
type BasicFeatureProvider ¶ added in v0.2.0
type BasicFeatureProvider interface { UserFeaturer ItemFeaturer }
type DashboardOverviewResult ¶
type FeatureOverview ¶
type FeatureOverview interface { // GetUsersFeatureOverview returns offset and size used for paging query GetUsersFeatureOverview(ctx context.Context, offset, size int, opts map[string][]string) (UserItemOverviewResult, error) // GetItemsFeatureOverview returns offset and size used for paging query GetItemsFeatureOverview(ctx context.Context, offset, size int, opts map[string][]string) (ItemOverviewResult, error) // GetDashboardOverview returns dashboard overview, see DashboardOverviewResult GetDashboardOverview(ctx context.Context) (DashboardOverviewResult, error) }
type Fitter ¶ added in v0.2.0
type Fitter interface {
Fit(sample *TrainSample) (PredictAbstract, error)
}
type ItemEmbedding ¶
ItemEmbedding is an interface used to generate item embedding with item2vec model by just providing a behavior based item sequence. Example: user liked items sequence, user bought items sequence, user viewed items sequence
type ItemFeaturer ¶
type ItemOverView ¶
type ItemOverviewResult ¶
type ItemOverviewResult struct {
Items []ItemOverView `json:"items"`
}
type PreTrainer ¶
type PredictAbstract ¶ added in v0.2.0
type Predictor ¶
type Predictor interface { BasicFeatureProvider PredictAbstract }
type RecApiRequest ¶
type RecApiResponse ¶
type RecApiResponse struct {
ItemScoreList []ItemScore `json:"itemScoreList"`
}
type RecSys ¶
type RecSys interface { BasicFeatureProvider Trainer }
type SampleInfo ¶ added in v0.2.0
type TrainSample ¶ added in v0.2.0
type TrainSample struct { X []float32 Y []float32 Rows int XCols int Info SampleInfo }
type UserBehavior ¶ added in v0.2.0
type UserBehavior interface { GetUserBehavior(ctx context.Context, userId int, maxLen int64, maxPk int64, maxTs int64) (itemSeq []int, err error) }
UserBehavior interface is used to get user behavior feature. typically, it is user's clicked/bought/liked item id list ordered by time desc. During training, you should limit the seq to avoid time travel,
maxPk or maxTs could be used here: - maxPk is the max primary key of user behavior table. - maxTs is the max timestamp of user behavior table. - maxLen is the max length of user behavior seq, if total len is greater than maxLen, the seq will be truncated from the tail. which is latest maxLen items.
specially, -1 means no limit. During prediction, you should use the latest user behavior seq.
type UserFeaturer ¶
type UserItemOverview ¶
type UserItemOverviewResult ¶
type UserItemOverviewResult struct {
Users []UserItemOverview `json:"users"`
}
Click to show internal directories.
Click to hide internal directories.