On Thu, Aug 30, 2018 at 9:41 PM Guido van Rossum <gu...@python.org> wrote:
> On Fri, Aug 31, 2018 at 3:19 AM, Michael Selik <m...@selik.org> wrote: > >> On Thu, Aug 30, 2018 at 5:31 PM James Lu <jam...@gmail.com> wrote: >> >>> It would be nice if there was a DSL for describing neural networks >>> (Keras). >>> >>> model.add(Dense(units=64, activation='relu', input_dim=100)) >>> model.add(Dense(units=10, activation='softmax')) >>> >>> >> Why not JSON or XML for cross-language compatibility? >> > > Presumably because those are even harder to read and write for humans. > Guido is absolutely right (as usual) that JSON or XML would be *vastly* harder to read than that very clean Python code. That said, if you wanted a "DSL", the perfect choice would be YAML. The description above could look like this: >>> model = ''' ... model: ... - layer: Dense ... units: 64 ... activation: relu ... input_dim: 100 ... - layer: Dense ... units: 10 ... activation: softmax ... ''' >>> yaml.load(model) {'model': [{'layer': 'Dense', 'units': 64, 'activation': 'relu', 'input_dim': 100}, {'layer': 'Dense', 'units': 10, 'activation': 'softmax'}]} This format could easily be either a string within a Python program or an external file with the definition. YAML is already well supported in Python, all you'd need to do is write a little wrapper to translate the description above into the actual Keras API calls, which would be pretty easy. -- Keeping medicines from the bloodstreams of the sick; food from the bellies of the hungry; books from the hands of the uneducated; technology from the underdeveloped; and putting advocates of freedom in prisons. Intellectual property is to the 21st century what the slave trade was to the 16th.
_______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/