Skip to main content

Implementation of zhang2016dependency

Project description

zhang2016dependency

This package provides a simple implementation of the models proposed in the paper:

Zhang, R., Lee, H., & Radev, D. (2016). Dependency sensitive convolutional neural networks for modeling sentences and documents. arXiv preprint arXiv:1611.02361.

Installation

This package depends on the Keras library. This means you will need to install a backend library in order to use this module. Take a look to Keras installation to get more information.

After having installed the backend of yout choice, you just need to install this package using pip:

pip install zhang2016dependency

Usage

This package only provides a single model. To get detailed information on the parameters the model accepts, take a look to the documentation included with the module class.

Here is a complete example of instantiation of the model proposed in the original paper using two channel of randomly initialized word embeddings:

import numpy as np
import numpy.random as rng

vocabulary_size = 1000
embedding_size = 300

value = np.sqrt(6/embedding_size)

weights_shape = (vocabulary_size+1, embedding_size)
weights = rng.uniform(low=-value, high=value, size=weights_shape)

channels = [
    {
      'weights': [weights],
      'trainable': False,
      'input_dim': vocabulary_size + 1,
      'output_dim': embedding_size,
      'name': 'random-embedding-1'
    },
    {
      'weights': [weights],
      'trainable': True,
      'input_dim': vocabulary_size + 1,
      'output_dim': embedding_size,
      'name': 'random-embedding-2'
    }
]

windows = [
    {
        'filters': 100,
        'kernel_size': 3,
        'activation': 'relu',
        'name': '3-grams'
    },
    {
        'filters': 100,
        'kernel_size': 4,
        'activation': 'relu',
        'name': '4-grams'
    },
    {
        'filters': 100,
        'kernel_size': 5,
        'activation': 'relu',
        'name': '5-grams'
    }
]

from zhang2016dependency import Model

model = Model(channels=channels,
              windows=windows,
              sentence_length=37,
              num_classes=6,
              dropout_rate=0.5,
              classifier_activation='softmax',
              include_top=True,
              name='DSCNN')

model.compile(optimizer='adadelta',
              loss='categorical_crossentropy',
              metrics=['accuracy'])

model.summary()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

zhang2016dependency-0.1.0.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

zhang2016dependency-0.1.0-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file zhang2016dependency-0.1.0.tar.gz.

File metadata

  • Download URL: zhang2016dependency-0.1.0.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.5.3

File hashes

Hashes for zhang2016dependency-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8bb28d57b710cd713cd93a5b9f95cf51e57f9906ec282e5a29bc8a4b33c72932
MD5 01e077500c7ecdf35615f57e78fdbb6b
BLAKE2b-256 0adb2e87c80c5d219700f546390ce53f1829cab4b8f550898a83bde14bd8ab5d

See more details on using hashes here.

File details

Details for the file zhang2016dependency-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: zhang2016dependency-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.5.3

File hashes

Hashes for zhang2016dependency-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c5596de3f35f91d9c7aed46164b53afa526ee438c5d995bb97d3fad5fc2fa841
MD5 180126e2fe138914e4e90d2dcf16373c
BLAKE2b-256 b564d44410b884c202266d6cde121303e3b3256d475462337d0d3227dc9bc28d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page