Re: [theano-users] What i do wrong when I use theano in production?

2017-03-25 Thread Jesse Livezey
Rather than using givens, and getting the batch through indexing, you can 
just have a theano variable be an input to your function. You should only 
need to compile the function once if your model does not change. You should 
be able to do something like this (you may need to modify this since I 
don't know what the rest of the code looks like)


predict_by_model = theano.function(inputs=[self.x],
   outputs=self.classifier.predict(self.y))

sentences = ['first', 'second', 'third']

for i in sentences:
new_data_by_i = get_data(i) # this is new data

res = predict_my_model(new_data_by_i)

where new_data_by_i should be a matrix or vector of data, not an index.

On Saturday, March 25, 2017 at 12:33:38 AM UTC-7, Нурислам Алимов wrote:
>
> Thanks Fred. 
>
> So, I am not fully understand how can I pickle compiled function. Because 
> lokk please in my code:
>
> def predict_by_model(data):
> test_model_predict = theano.function(inputs=[self.start_idx, self.
> end_idx],
>  outputs=self.classifier.predict(self.y),
>  givens={
>  self.x: data_x[self.start_idx:self.end_idx],
>  self.y: data_y[self.start_idx:self.end_idx]})
>
> test_predictions = test_model_predict(0, len(test_set[1]))
>
> sentences = ['first', 'second', 'third']
>
> for i in sentences:
> new_data_by_i = get_data(i) # this is new data
>
> res = predict_my_model(new_data_by_i)
>
> Everytime in the loop I have new data. I think I can't precompile 
> functions because I don't know what data I will get in next time? 
>
> Or I'm wrong and there is another way.
>
> Thanks for you help.
>
>
>
> суббота, 25 марта 2017 г., 1:09:14 UTC+3 пользователь nouiz написал:
>>
>> It depend of your production environment. But you can start a server with 
>> multiple process and they compile the function when the process is started, 
>> but you reuse it for many function call.
>>
>> You can also pickle the Theano function and have the process unpickle it. 
>> It would be faster then recompile it. This do not remove any tho 
>> dependencies.
>>
>> Fred
>>
>> Le ven. 24 mars 2017 05:47, Нурислам Алимов  a 
>> écrit :
>>
>>> I use this code in parallel. Is it correct?
>>>
>>>
>>> test_model_predict = theano.function(inputs=[self.start_idx, self.
>>> end_idx],
>>>  outputs=self.classifier.predict(self.y),
>>>  givens={
>>>  self.x: test_set_x[self.start_idx:self.end_idx],
>>>  self.y: test_set_y[self.start_idx:self.end_idx]})
>>>
>>>
>>> test_predictions = test_model_predict(0, len(test_set[1]))
>>>
>>> How can I call predictions of model without use theano.function - 
>>> because it is not thread safe function as I know and it is very long.
>>>
>>> Please help.
>>>
>>> -- 
>>>
>>> --- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "theano-users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to theano-users...@googlegroups.com.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"theano-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to theano-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [theano-users] What i do wrong when I use theano in production?

2017-03-25 Thread Нурислам Алимов
Thanks Fred. 

So, I am not fully understand how can I pickle compiled function. Because 
lokk please in my code:

def predict_by_model(data):
test_model_predict = theano.function(inputs=[self.start_idx, self.
end_idx],
 outputs=self.classifier.predict(self.y),
 givens={
 self.x: data_x[self.start_idx:self.end_idx],
 self.y: data_y[self.start_idx:self.end_idx]})

test_predictions = test_model_predict(0, len(test_set[1]))

sentences = ['first', 'second', 'third']

for i in sentences:
new_data_by_i = get_data(i) # this is new data

res = predict_my_model(new_data_by_i)

Everytime in the loop I have new data. I think I can't precompile functions 
because I don't know what data I will get in next time? 

Or I'm wrong and there is another way.

Thanks for you help.



суббота, 25 марта 2017 г., 1:09:14 UTC+3 пользователь nouiz написал:
>
> It depend of your production environment. But you can start a server with 
> multiple process and they compile the function when the process is started, 
> but you reuse it for many function call.
>
> You can also pickle the Theano function and have the process unpickle it. 
> It would be faster then recompile it. This do not remove any tho 
> dependencies.
>
> Fred
>
> Le ven. 24 mars 2017 05:47, Нурислам Алимов  > a écrit :
>
>> I use this code in parallel. Is it correct?
>>
>>
>> test_model_predict = theano.function(inputs=[self.start_idx, self.end_idx
>> ],
>>  outputs=self.classifier.predict(self.y),
>>  givens={
>>  self.x: test_set_x[self.start_idx:self.end_idx],
>>  self.y: test_set_y[self.start_idx:self.end_idx]})
>>
>>
>> test_predictions = test_model_predict(0, len(test_set[1]))
>>
>> How can I call predictions of model without use theano.function - because 
>> it is not thread safe function as I know and it is very long.
>>
>> Please help.
>>
>> -- 
>>
>> --- 
>> You received this message because you are subscribed to the Google Groups 
>> "theano-users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to theano-users...@googlegroups.com .
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"theano-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to theano-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [theano-users] What i do wrong when I use theano in production?

2017-03-24 Thread Frédéric Bastien
It depend of your production environment. But you can start a server with
multiple process and they compile the function when the process is started,
but you reuse it for many function call.

You can also pickle the Theano function and have the process unpickle it.
It would be faster then recompile it. This do not remove any tho
dependencies.

Fred

Le ven. 24 mars 2017 05:47, Нурислам Алимов  a écrit :

> I use this code in parallel. Is it correct?
>
>
> test_model_predict = theano.function(inputs=[self.start_idx, self.end_idx
> ],
>  outputs=self.classifier.predict(self.y),
>  givens={
>  self.x: test_set_x[self.start_idx:self.end_idx],
>  self.y: test_set_y[self.start_idx:self.end_idx]})
>
>
> test_predictions = test_model_predict(0, len(test_set[1]))
>
> How can I call predictions of model without use theano.function - because
> it is not thread safe function as I know and it is very long.
>
> Please help.
>
> --
>
> ---
> You received this message because you are subscribed to the Google Groups
> "theano-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to theano-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"theano-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to theano-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.