jncraton / languagemodels

Explore large language models in 512MB of RAM
https://jncraton.github.io/languagemodels/
MIT License
1.18k stars 78 forks source link

Mathematical Operations Solver in Natural Language (Bug Fixed) #16

Closed DannyLuna17 closed 1 year ago

DannyLuna17 commented 1 year ago

I've implemented a calculator feature that provides solutions to mathematical operations in natural language. This can be particularly beneficial for educators in the exact sciences.

Support simplifications, derivative, integral, limits, eigenvalues, etc.

Examples:

>>> calculate("2*x=6") # returns "x is 3"
>>> calculate("integrate x**2 x")  # Returns "The integral of x**2 with respect to x is x**3/3"
>>> calculate("limit x**2/x x +"))  # Returns "The limit of x**2/x as x approaches +∞ is ∞"
jncraton commented 1 year ago

I see the value of this, but I'm hesitant to bring it in as a core part of the package. I'd like to avoid dependencies like SymPy, as I expect that most users of this package are using it for simple access to a language model and won't end up needing symbolic math.

This package is built around interacting with a language model via prompting. There are a few ancillary tools provided to help simplify the process of augmenting prompts, but they are relatively lightweight and do not require additional dependencies.

I could see adding something like the calculator you've implemented as a way to easily demonstrate tool usage without resorting to eval, but I don't think that the models in use here currently would be capable of appropriately requesting an integral from a story problem. As far as I can tell, they are just barely able to request basic arithmetic operations (as in the tools example). A basic calculator might make more sense.

Perhaps this could be reworked into one of the examples showing how SymPy could be used in conjunction with this package?

DannyLuna17 commented 1 year ago

Oh, fine, i understand, good luck, with your proyect!