tensorflow / models

Models and examples built with TensorFlow
Other
77.24k stars 45.75k forks source link

Importing syntaxnet from Python #148

Closed korkinof closed 8 years ago

korkinof commented 8 years ago

Hi guys, I've built syntaxnet and was able to run the demo. How do I import the package from python? I think I can see python wrappers in the build, but cannot seem to be able to import the whole thing. Can anyone help? Thanks in advance! Best, D.

andorardo commented 8 years ago

Hi Dimitrios,

We don't currently suggest a single official way to run SyntaxNet from Python. One simple approach is to spawn SyntaxNet as a subprocess, as done here. But you could wrap it in a Python module, or even call the TensorFlow graph from C++, without any Python.

Cheers, Daniel

Hema414 commented 8 years ago

Hi andorado, Can you please provide some details about how to call the TensorFlow graph from C++, i read the tensorflow tutorials about it, but couldn't figure out how this could be applied to syntaxnet.

micimize commented 7 years ago

the currently recommended way to use syntaxnet from python is via DRAGNN

srinathperera commented 7 years ago

Hi micimize,

I got the docker image started as described in the link, and then able to run the demo.sh. However, still cannot figure out how can I run the model from vanila python. Are there any resources that can help?

--Srinath

micimize commented 7 years ago

@srinathperera I've only gotten it working via bazel and docker with the following BUILD:

py_binary(
    name = "app",
    main = "src/__main__.py",
    srcs = ["src/__main__.py"],
    deps = [":deps"],
)

py_library(
    name = "deps",
    deps = [
        "//dragnn/core:dragnn_bulk_ops",
        "//dragnn/core:dragnn_ops",
        "//dragnn/protos:spec_py_pb2",
        "//dragnn/python:graph_builder",
        "//dragnn/python:lexicon",
        "//dragnn/python:load_dragnn_cc_impl_py",
        "//dragnn/python:spec_builder",
        "//dragnn/python:visualization",
        "//syntaxnet:load_parser_ops_py",
        "//syntaxnet:parser_ops",
        "//syntaxnet:sentence_py_pb2",
        "@org_tensorflow//tensorflow:tensorflow_py",
        "@org_tensorflow//tensorflow/core:protos_all_py",
    ],
)

and Dockerfile:

FROM tensorflow/syntaxnet

ENV SYNTAXNETDIR=/opt/tensorflow
ENV WORKDIR=$SYNTAXNETDIR/syntaxnet/journal

RUN mkdir -p $WORKDIR/src

WORKDIR $WORKDIR

COPY src ./src
COPY data ./data
COPY requirements.txt ./
COPY BUILD            ./

RUN apt-get install -y coreutils
RUN python -m pip install -r requirements.txt

CMD /bin/bash -c "bazel run app"