{"id":21188,"library":"dynet","title":"DyNet","description":"DyNet is the Dynamic Neural Network Toolkit, a C++ library with Python bindings for training neural networks, particularly focused on natural language processing. Current version 2.1.2 supports implicitly cast parameters as expressions, Python 3.8+, and advanced slicing. Release cadence is irregular.","status":"active","version":"2.1.2","language":"python","source_language":"en","source_url":"https://github.com/clab/dynet","tags":["deep learning","neural networks","nlp","C++ backend"],"install":[{"cmd":"pip install dynet","lang":"bash","label":"Install from PyPI"}],"dependencies":[],"imports":[{"note":"Wildcard imports pollute namespace; convention is to import as dy.","wrong":"from dynet import *","symbol":"dynet","correct":"import dynet as dy"},{"note":"dynet.Model is not a submodule; directly import the class.","wrong":"import dynet.Model","symbol":"Model","correct":"from dynet import Model"}],"quickstart":{"code":"import dynet as dy\n\nmodel = dy.Model()\ntrainer = dy.SimpleSGDTrainer(model)\npW = model.add_parameters((2, 2))\npb = model.add_parameters(2)\n\nx = dy.vecInput(2)\ny = dy.scalarInput(0)\n\nfor epoch in range(5):\n    loss = dy.pickneglogsoftmax(pW.expr() * x, y)\n    loss.backward()\n    trainer.update()\n    print(f\"Epoch {epoch}: loss = {loss.value()}\")","lang":"python","description":"Minimal example: create a model, parameters, and perform a simple optimization loop."},"warnings":[{"fix":"Use `p` instead of `p.expr()` or `dy.parameter(p)`.","message":"In DyNet 2.1, parameters are implicitly cast to expressions. Do not call `dy.parameter(p)` or `p.expr()`; just use `p` directly.","severity":"gotcha","affected_versions":">=2.1"},{"fix":"Retrain models with v2.0+ or use a conversion script (if available).","message":"DyNet 2.0 removed dependency on Boost. Model files saved with v1.x are incompatible. You must re-train or convert models.","severity":"breaking","affected_versions":">=2.0"},{"fix":"Call `dy.renew_cg()` at the start of each training iteration.","message":"Always call `dy.renew_cg()` before creating new computation graph nodes in a loop, otherwise memory usage grows unbounded.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Run `pip install dynet` and ensure you are using the correct Python interpreter.","cause":"DyNet not installed or Python environment not correct.","error":"ImportError: No module named dynet"},{"fix":"In DyNet >=2.1 just use `p` (not `p()` or `p.expr()`). In older versions use `p.expr()`.","cause":"Using `p()` instead of `p.expr()` in DyNet <2.1, or using `p.expr()` in DyNet >=2.1 where parameters are already expressions.","error":"TypeError: 'Parameter' object is not callable"},{"fix":"Call `dy.renew_cg()` before each training iteration or when building a new graph.","cause":"Attempting to reuse a computation graph without calling `dy.renew_cg()`.","error":"ValueError: The model has already been trained, or the computation graph has already been built."}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}