forked from manifoldmarkets/manifold
-
Notifications
You must be signed in to change notification settings - Fork 0
/
feed.ts
186 lines (173 loc) · 6.29 KB
/
feed.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
// User interest to user interest distance:
import { sum } from 'lodash'
export const MINIMUM_SCORE = 0.0035
export const DEFAULT_FEED_USER_ID = 'yYNDWRmBJDcWW0q1aZFi6xfKNcQ2'
export const ALL_FEED_USER_ID = 'IG3WZ8i3IzY6R4wuTDxuvsXbkxD3'
export type FEED_DATA_TYPES =
| 'new_comment'
| 'news_with_related_contracts'
| 'new_contract'
| 'contract_probability_changed'
| 'trending_contract'
| 'new_subsidy'
| 'user_position_changed'
type DEPRECATED_FEED_REASON_TYPES =
| 'viewed_contract'
| 'similar_interest_vector_to_user'
// TODO: add 'shared_contract'
export type CONTRACT_FEED_REASON_TYPES =
| 'follow_contract'
| 'liked_contract'
| 'contract_in_group_you_are_in'
| 'similar_interest_vector_to_contract'
| 'follow_user'
export type FEED_REASON_TYPES =
| CONTRACT_FEED_REASON_TYPES
| 'similar_interest_vector_to_news_vector'
export const NEW_USER_FEED_DATA_TYPES: FEED_DATA_TYPES[] = [
'new_contract',
'contract_probability_changed',
'trending_contract',
'new_subsidy',
]
export const BASE_FEED_DATA_TYPE_SCORES: { [key in FEED_DATA_TYPES]: number } =
{
new_comment: 0.05,
new_contract: 0.15,
new_subsidy: 0.1,
news_with_related_contracts: 0.1,
user_position_changed: 0.05,
contract_probability_changed: 0.2, // todo: multiply by magnitude of prob change
trending_contract: 0.2,
}
export const BASE_FEED_REASON_TYPE_SCORES: {
[key in FEED_REASON_TYPES]: number
} = {
follow_contract: 0.4,
liked_contract: 0.2,
contract_in_group_you_are_in: 0.2,
similar_interest_vector_to_contract: 0, // score calculated using interest distance
follow_user: 0.3,
similar_interest_vector_to_news_vector: 0.1,
}
export const getRelevanceScore = (
feedDataType: FEED_DATA_TYPES,
reasons: FEED_REASON_TYPES[],
importanceScore: number,
interestDistance: number,
trendingContractType?: 'old' | 'new'
): number => {
const dataTypeScore =
trendingContractType === 'old'
? 0
: BASE_FEED_DATA_TYPE_SCORES[feedDataType]
const reasonsScore = sum(reasons.map((r) => BASE_FEED_REASON_TYPE_SCORES[r]))
return (
dataTypeScore +
reasonsScore +
importanceScore * 0.3 +
(1 - interestDistance) * 0.2
)
}
export type CreatorDetails = {
id: string
name: string
username: string
avatarUrl: string
}
export const INTEREST_DISTANCE_THRESHOLDS: Record<
FEED_DATA_TYPES | 'ad',
number
> = {
contract_probability_changed: 0.13,
trending_contract: 0.15,
new_contract: 0.125,
new_comment: 0.115,
news_with_related_contracts: 0.175, // used to compare user interest vector to news title embedding
new_subsidy: 0.15,
user_position_changed: 1, // only targets followed users,
ad: 0.175,
}
export const FeedExplanationDictionary: Record<
FEED_DATA_TYPES,
Partial<Record<FEED_REASON_TYPES | DEPRECATED_FEED_REASON_TYPES, string>>
> = {
new_comment: {
follow_contract: 'New comment on question you follow',
liked_contract: 'New comment on question you liked',
viewed_contract: 'New comment on question you viewed',
contract_in_group_you_are_in:
'New comment on question in a group you are in',
similar_interest_vector_to_user:
'New comment by a creator you may be interested in',
similar_interest_vector_to_contract:
'New comment on a question you may be interested in',
follow_user: 'New comment by a creator you follow',
},
news_with_related_contracts: {
follow_contract: 'News about question you follow',
liked_contract: 'News about question you liked',
viewed_contract: 'News about question you viewed',
contract_in_group_you_are_in: 'News about question in a group you are in',
similar_interest_vector_to_user:
'News related to a creator you may be interested in',
similar_interest_vector_to_contract:
'News related to a question you may be interested in',
follow_user: 'News about a question by a creator you follow',
similar_interest_vector_to_news_vector: 'News you may be interested in',
},
new_contract: {
contract_in_group_you_are_in: 'New question in a group you are in',
similar_interest_vector_to_user:
'New question by a creator you may be interested in',
similar_interest_vector_to_contract:
'New question you may be interested in',
follow_user: 'New question by a creator you follow',
},
contract_probability_changed: {
follow_contract: 'Market movement on question you follow',
liked_contract: 'Market movement on question you liked',
viewed_contract: 'Market movement on question you viewed',
contract_in_group_you_are_in:
'Market movement on question in a group you are in',
similar_interest_vector_to_user:
'Market movement on question by a creator you may be interested in',
similar_interest_vector_to_contract:
'Market movement on question you may be interested in',
follow_user: 'Market movement on question by a creator you follow',
},
trending_contract: {
follow_contract: 'Trending question you follow',
liked_contract: 'Trending question you liked',
viewed_contract: 'Trending question you viewed',
contract_in_group_you_are_in: 'Trending question in a group you are in',
similar_interest_vector_to_user:
'Trending question by a creator you may be interested in',
similar_interest_vector_to_contract:
'Trending question you may be interested in',
follow_user: 'Trending question by a creator you follow',
},
new_subsidy: {
contract_in_group_you_are_in:
'New subsidy on question in a group you are in',
similar_interest_vector_to_user:
'New subsidy by a creator you may be interested in',
similar_interest_vector_to_contract:
'New subsidy on a question you may be interested in',
follow_user: 'New subsidy by a creator you follow',
},
user_position_changed: {
contract_in_group_you_are_in: 'New bets on question in a group you are in',
similar_interest_vector_to_user:
'New bets by a creator you may be interested in',
similar_interest_vector_to_contract:
'New bets on a question you may be interested in',
follow_user: 'New bets by a creator you follow',
},
}
export function getExplanation(
feedDataType: FEED_DATA_TYPES,
feedReasonType: FEED_REASON_TYPES | DEPRECATED_FEED_REASON_TYPES
): string | undefined {
return FeedExplanationDictionary[feedDataType][feedReasonType]
}