ericproffitt / TopicModelsVB.jl

A Julia package for variational Bayesian topic modeling.
Other
81 stars 8 forks source link

UndefVarError: .+ not defined #24

Closed ValeriiBaidin closed 4 years ago

ValeriiBaidin commented 4 years ago

julia ver. 1.1.1

UndefVarError: .+ not defined

Stacktrace:
 [1] update_elbo!(::LDA) at /home/vbaidin/.julia/packages/TopicModelsVB/09DyQ/src/LDA.jl:91
 [2] LDA(::TopicModelsVB.Corpus, ::Int64) at /home/vbaidin/.julia/packages/TopicModelsVB/09DyQ/src/LDA.jl:42
 [3] top-level scope at In[35]:1
ericproffitt commented 4 years ago

Hi Valerii,

Can you please provide me with a minimal code sample with which I can replicate this error.

ValeriiBaidin commented 4 years ago

I don't have problem on my computer. It works perfectly. But on server, I have these errors. I will give little example later. That code is too big to copy. model = LDA(corpus_t, 10)

ericproffitt commented 4 years ago

If it works on your computer, but not on your server, then it may have to do with the Linux distribution of Julia.

If I'm not able to replicate the error on my computer, then it may be difficult or impossible for me to fix.

Have you tried upgrading Julia to the latest version, to see if that fixes it?

ValeriiBaidin commented 4 years ago

If it works on your computer, but not on your server, then it may have to do with the Linux distribution of Julia.

If I'm not able to replicate the error on my computer, then it may be difficult or impossible for me to fix.

Yes, I understand it.

But do you know your code in the lines? What can cause the error?

ericproffitt commented 4 years ago

So that line is modified by an internal macro. The code is,

@positive model.phi[1] = model.beta_old[:,terms] .* exp.(model.Elogtheta_old[d])

Which should result in the following expression at compile time,

model.phi[1] = EPSILON .+ model.beta_old[:,terms] .* exp.(model.Elogtheta_old[d])
ericproffitt commented 4 years ago

Are you able to to perform coordinate-wise addition of a scalar with an array on your server's version of Julia?

ValeriiBaidin commented 4 years ago

Maybe it can be useful

WARNING: Method definition additive_logistic(Array{#s17, 2} where #s17<:Real) in module TopicModelsVB at /home/vbaidin/.julia/packages/TopicModelsVB/09DyQ/src/utils.jl:113 overwritten at /home/vbaidin/.julia/packages/TopicModelsVB/09DyQ/src/utils.jl:135.
WARNING: Method definition binomlogpdf(Real, Real, Real) in module StatsFuns at /home/vbaidin/.julia/packages/StatsFuns/CXyCV/src/distrs/binom.jl:19 overwritten in module TopicModelsVB at /home/vbaidin/.julia/packages/TopicModelsVB/09DyQ/src/utils.jl:164.
WARNING: Method definition entropy(Distributions.Dirichlet{T} where T<:Real) in module Distributions at /home/vbaidin/.julia/packages/Distributions/ZJ0hQ/src/multivariate/dirichlet.jl:118 overwritten in module TopicModelsVB at /home/vbaidin/.julia/packages/TopicModelsVB/09DyQ/src/utils.jl:168.
WARNING: Method definition (::Type{TopicModelsVB.Corpus})(Array{TopicModelsVB.Document, 1}) in module TopicModelsVB at /home/vbaidin/.julia/packages/TopicModelsVB/09DyQ/src/Corpus.jl:76 overwritten at /home/vbaidin/.julia/packages/TopicModelsVB/09DyQ/src/Corpus.jl:77.
WARNING: Method definition (::Type{TopicModelsVB.Corpus})(TopicModelsVB.Document) in module TopicModelsVB at /home/vbaidin/.julia/packages/TopicModelsVB/09DyQ/src/Corpus.jl:78 overwritten at /home/vbaidin/.julia/packages/TopicModelsVB/09DyQ/src/Corpus.jl:79.
ValeriiBaidin commented 4 years ago

this is a simple exercise, with the same problem

c= Corpus([Document([1,2,3]),Document([1,2,3]),Document([1,2,3]),Document([1,2,3]),
            Document([4,5,6]),Document([4,5,6]),Document([4,5,6]),Document([4,5,6]),
            Document([7,7,7]),Document([7,7,7]),Document([7,7,7]),Document([7,7,7])],
            vocab = split("1 2 3 4 5 6 7"))
model = LDA(c, 2)
ericproffitt commented 4 years ago
c= Corpus([Document([1,2,3]),Document([1,2,3]),Document([1,2,3]),Document([1,2,3]),
            Document([4,5,6]),Document([4,5,6]),Document([4,5,6]),Document([4,5,6]),
            Document([7,7,7]),Document([7,7,7]),Document([7,7,7]),Document([7,7,7])],
            vocab = split("1 2 3 4 5 6 7"))
model = LDA(c, 2)

This code works fine for me on the MacOS distribution of Julia 1.4.2.

ValeriiBaidin commented 4 years ago
c= Corpus([Document([1,2,3]),Document([1,2,3]),Document([1,2,3]),Document([1,2,3]),
            Document([4,5,6]),Document([4,5,6]),Document([4,5,6]),Document([4,5,6]),
            Document([7,7,7]),Document([7,7,7]),Document([7,7,7]),Document([7,7,7])],
            vocab = split("1 2 3 4 5 6 7"))
model = LDA(c, 2)

This code works fine for me on the MacOS distribution of Julia 1.4.2.

it works on Julia 1.3 on my PC.

So is the problem of Julia 1.1.1? Can I do something to patch it?

ericproffitt commented 4 years ago

If you unable to upgrade your server's version of Julia (which may or may not fix the problem), then patching your copy of TopicModelsVB.jl will be difficult if the problem is the element-wise addition operator, since that operator is used in many places in the source code.

So even if you manually fix this particular line, the error will just then pop up somewhere else. Can you please run the following code on your server, and let me know if it works:

3 .+ [1 2; 3 4]
ValeriiBaidin commented 4 years ago

If you unable to upgrade your server's version of Julia (which may or may not fix the problem), then patching your copy of TopicModelsVB.jl will be difficult if the problem is the element-wise addition operator, since that operator is used in many places in the source code.

So even if you manually fix this particular line, the error will just then pop up somewhere else. Can you please run the following code on your server, and let me know if it works:

3 .+ [1 2; 3 4]

Thank you for your help.

it works perfectly.

ericproffitt commented 4 years ago

Ok, now can you please try this code:

EPSILON = 1

macro positive(expr::Expr)
    "Add EPSILON to a numerical variable or array during variable assignment."

    if (expr.head == :.) || (expr.head == :ref)
        expr_out = :(:($($expr)) .+= EPSILON)

    elseif expr.head == :(=)
        expr_out = :(:($($(expr.args[1]))) = EPSILON .+ :($($(expr.args[2]))))
    end

    return expr_out
end

@positive x = 3

The result should be 4.

And then if that works, try this:

@positive x = [1 2; 3 4]
ValeriiBaidin commented 4 years ago

Ok, now can you please try this code:

EPSILON = 1

macro positive(expr::Expr)
  "Add EPSILON to a numerical variable or array during variable assignment."

  if (expr.head == :.) || (expr.head == :ref)
      expr_out = :(:($($expr)) .+= EPSILON)

  elseif expr.head == :(=)
      expr_out = :(:($($(expr.args[1]))) = EPSILON .+ :($($(expr.args[2]))))
  end

  return expr_out
end

@positive x = 3

The result should be 4.

And then if that works, try this:

@positive x = [1 2; 3 4]

the same error

UndefVarError: .+ not defined

Stacktrace:
 [1] top-level scope at In[6]:15
ericproffitt commented 4 years ago

Which gave you the error, @positive x = 3 or @positive x = [1 2; 3 4]?

ValeriiBaidin commented 4 years ago

Which gave you the error, @positive x = 3 or @positive x = [1 2; 3 4]?

The first, I can't even define the macro

ericproffitt commented 4 years ago

Ok, so this is something I will need to discuss with the Julia Dev team, and then I can get back to you hopefully with a solution at a future date.

In the mean time, my only suggestion is to try upgrading Julia to the latest version (if you can), as that may fix the issue.

ValeriiBaidin commented 4 years ago

Thank. Unfortunately, I can't update it right now. =(

Thank you for your help.

ValeriiBaidin commented 4 years ago
macro test_macro(e::Expr)
    return esc( :( ones(size($e)[1]) .+ $e) )
end

@test_macro [1 2 ; 3 4]

This code works on Julia ver 1.1.1

ericproffitt commented 4 years ago

Could you try out the following code on your command line:

macro positive(expr::Expr)
    "Add EPSILON to a numerical variable or array during variable assignment."

    if (expr.head == :.) || (expr.head == :ref)
        expr_out = :($expr .+= EPSILON)

    elseif expr.head == :(=)
        expr_out = :($(expr.args[1]) = EPSILON .+ $(expr.args[2]))
    end

    return expr_out
end

If it works, then you could try patching the macros.jl file by replacing the positive macro with the above.

It appears to be working for my preliminary tests, but I'll need to test it further before I open a PR.

ValeriiBaidin commented 4 years ago

Try out the following code on your command line:

macro positive(expr::Expr)
  "Add EPSILON to a numerical variable or array during variable assignment."

  if (expr.head == :.) || (expr.head == :ref)
      expr_out = :($expr .+= EPSILON)

  elseif expr.head == :(=)
      expr_out = :($(expr.args[1]) = EPSILON .+ $(expr.args[2]))
  end

  return expr_out
end

If it works, then you could try patching the macros.jl file by replacing the positive macro with the above.

It appears to be working for my preliminary tests, but I'll need to test it further before I open a PR.

Unfortunately, it doesn't work. But the next code works!!!!

EPSILON = 1
macro positive(expr::Expr)
    "Add EPSILON to a numerical variable or array during variable assignment."
    if (expr.head == :.) || (expr.head == :ref)
        expr_out =  :($expr .+= EPSILON)

    elseif expr.head == :(=)
        expr_out =  :($(expr.args[1]) = EPSILON .+ $(expr.args[2])) 
    end
    return  esc( expr_out )
end
ericproffitt commented 4 years ago

Ok so I did find this related dicussion concerning unresolved issues in Julia's metaprogramming functionality.

If escaping the return value is what's fixing the problem for you, then a potential patch would be to go into macros.jl and replace return expr_out with return esc(expr_out) for the following macros:

macro juliadots(str::String)
macro juliadots(expr::Expr)
macro boink(expr::Expr)
macro positive(expr::Expr)
macro finite(expr::Expr)
ericproffitt commented 4 years ago

Ok, so I've modified the offending macros.

You can see the changes made here https://github.com/ericproffitt/TopicModelsVB.jl/commit/fcd6f8d6d4cf93a5c74b18ba33098dc8473323e9.

Could you let me know if this fixes the problem for you?

ValeriiBaidin commented 4 years ago

Ok, so I've modified the offending macros.

You can see the changes made here fcd6f8d.

Could you let me know if this fixes the problem for you?

thank you.

Shall I replace only macro.jl file, or should I update the whole package?

P.S. right now, I am working with my hand fixing macro. jl

ericproffitt commented 4 years ago

The changes have been committed to the master branch.

So if you just run,

pkg> add https://github.com/ericproffitt/TopicModelsVB.jl

Then you should be good to go, no need to modify the macros.jl file yourself.

ValeriiBaidin commented 4 years ago

The changes have been committed to the master branch.

So if you just run,

pkg> add https://github.com/ericproffitt/TopicModelsVB.jl

Then you should be good to go, no need to modify the macros.jl file yourself.

Thank you, I will check a lit bit later.

Thank you so much

ericproffitt commented 4 years ago

I'm going to close this issue, if you're still having problems with the macro functionality, please feel free to reopen.