@@ -29,7 +29,6 @@ import Data.Function (on)
2929import Data.List (foldl' , maximumBy , sort , sortBy )
3030import qualified Data.Map.Strict as M
3131import Data.Maybe
32- import Data.Ollama.Generate
3332import qualified Data.Text as T
3433import Data.Type.Equality
3534import qualified Data.Vector as V
@@ -185,54 +184,6 @@ numericCols df = concatMap extract (columnNames df)
185184 SFalse -> []
186185 _ -> []
187186
188- instructions :: String
189- instructions =
190- " You must output ONLY a single digit 0-10, nothing else. No explanation, no text, just the number. \n "
191- ++ " Rate whether this expression produces a meaningful real-world quantity: \n "
192- ++ " Evaluate if this expression produces a meaningful quantity by checking:\n "
193- ++ " - Do the units/types match for the operation?\n "
194- ++ " - Is either operand a categorical code rather than a true quantity?\n "
195- ++ " - Would the result be useful to actually calculate?\n "
196- ++ " Scoring: \n "
197- ++ " - 0-3: Result is meaningless (e.g., \" fare + age\" = dollars+years, \" height + weight\" = meters+kg)\n "
198- ++ " - 4-5: Unclear or context-dependent meaning\n "
199- ++ " - 6-7: Makes sense in specific domains\n "
200- ++ " - 8-9: Clear, commonly useful quantity\n "
201- ++ " - 10: Fundamental/universal quantity\n "
202- ++ " Guidelines:\n "
203- ++ " - Addition/subtraction: operands must represent the same kind of thing\n "
204- ++ " - Multiplication/division: can create meaningful derived quantities\n "
205- ++ " - Consider: would this result be useful to calculate in practice?\n "
206- ++ " - `toDouble` is just a function that converts any number to a decimal and is semantically unimportant.\n "
207- ++ " Examples:\n "
208- ++ " toDouble(fare) + toDouble(age) = 2 (adding money to years)\n "
209- ++ " toDouble(price) / toDouble(area) = 9 (price per sq ft)\n "
210- ++ " toDouble(distance) / toDouble(time) = 10 (speed)\n "
211- ++ " toDouble(num_people) * toDouble(rejection_rate) = 9 (expected rejections)\n "
212- ++ " toDouble(revenue) - toDouble(costs) = 10 (profit)\n "
213- ++ " toDouble(height) + toDouble(weight) = 2 (adding length to mass)\n "
214- ++ " Output format: Just the digit, e.g., 2\n "
215- ++ " Think very carefully about each but only give me the final answer.\n "
216- ++ " Expression: "
217-
218- score :: Expr a -> Int
219- score expr =
220- let
221- genOp =
222- defaultGenerateOps
223- { modelName = " llama3"
224- , prompt = T. pack (instructions ++ prettyPrint expr)
225- }
226- llamaConfig = Just (defaultOllamaConfig{hostUrl = " http://127.0.0.1:8080" })
227- result = unsafePerformIO $ try @ SomeException (generate genOp llamaConfig)
228- in
229- case result of
230- Right (Right response) ->
231- let llmResponse = genResponse response
232- s = fst $ either error id $ decimal @ Int llmResponse
233- in trace (prettyPrint expr ++ " : " ++ show s) s
234- _ -> 7
235-
236187numericExprs ::
237188 SynthConfig -> DataFrame -> [Expr Double ] -> Int -> Int -> [Expr Double ]
238189numericExprs cfg df prevExprs depth maxDepth
@@ -256,8 +207,7 @@ numericExprs cfg df prevExprs depth maxDepth
256207 (disallowedCombinations cfg)
257208 )
258209 )
259- concat [[e1 + e2, e1 - e2] | score (e1 + e2) > 5 ]
260- ++ concat [[e1 * e2, F. ifThenElse (e2 ./= 0 ) (e1 / e2) 0 ] | score (e1 * e2) > 5 ]
210+ [e1 + e2, e1 - e2, e1 * e2, F. ifThenElse (e2 ./= 0 ) (e1 / e2) 0 ]
261211
262212boolExprs ::
263213 DataFrame -> [Expr Bool ] -> [Expr Bool ] -> Int -> Int -> [Expr Bool ]
0 commit comments