GithubHelp home page GithubHelp logo

Comments (4)

justheuristic avatar justheuristic commented on June 19, 2024 1

Hi!

short:
We also pad sequences to the same length, this is done in the as_matrix function.

long:
The padding is usually done out of one of two reasons:

  1. to put several strings in one tensorflow tensor (matrix)
  2. to compensate for model's inability to process sequences of different length.

The model we want you to build is able to process sequences of arbitrary length greater than conv filter size, so the only reason is (1.).

Instead of padding all data to a fixed length, we pad sequences when the batch is formed (in as_matrix function). For instance, if there are three sentences in batch, their lengths being [3, 7, 5], they all will be padded to length=7.
However, if the next batch has different sequence lengths, they will be padded to a maximum of batch's sequence lengths.

The default network architecture is applicable to a batch of arbitrary length:

  • first you apply convolutions/pooling which are applied to each patch of arbitrarily long sequence
  • then you take whatever is left after convolution and do global max/average pooling, computing max/mean over time for each channel. Thus if convolution output shape was [batch_size, time, num_filters], it will be reduced to [batch_size, num_filters] and will become length independent.
  • finally you apply dense layers to this fixed size representation

The only catch is that input must be long enough to apply convolutions. This should not be a problem if you use filter sizes of 2 or 3. For larger filters, please pad shorter sequences by either setting as_matrix(..., max_length=your_max_length) or just manually add dots (. . . . .) to shorter job titles.

from nlp_course.

LB-Yu avatar LB-Yu commented on June 19, 2024

Thank you very much for your detailed answer.

"This should not be a problem if you use filter sizes of 2 or 3."-Did you mean use square filter of the conv layer? If use a square filter then I know how to solve the problem.

However, I read the paper A Sensitivity Analysis of (and Practitioners' Guide to) Convolutional Neural Networks for Sentence Classification. And in section 2.1, the author said "Because rows represent discrete symbols (namely, words), it is reasonable to use filters with widths equal to the dimensionality of the word vectors (i.e., d)." I think it's reasonable to use filters with widths equal to the dimensionality of the word vectors. Will it reduce the interpretability of the network, if we use suqare filters?

Thank you again for your answer!

from nlp_course.

justheuristic avatar justheuristic commented on June 19, 2024

In this particular case we use 1D convolutions, so our filters are not squares, they're just 1d "stripes".

You can also consider this to be equivalent to using filters of dimension [vector_size x width] where vector size equals length of word embedding vectors and width is something around 2 or 3.

For this task it doesn't make much sense to use filter width equal to vector size because

  • vector size can be large, several hundreds
  • job title may contain 2-20 tokens, which is much smaller than vector size

from nlp_course.

LB-Yu avatar LB-Yu commented on June 19, 2024

from nlp_course.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.