AttributeError: 'dict' object has no attribute 'to' - bert-language-model

I used an example of using BERT to classify reviews, described at the link. The code is written for using the CPU and it works fine, but slowly. In Colab Google, with a multilingual model, one epoch is considered 4 hours for me. If I replace the CPU with the CUDA everywhere in the code, then the error that YOU met with appears. I followed the guidelines given in the link, but then another error appears:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-3-0b35a5f74768> in <module>()
268 'labels': batch[2],
269 }
--> 270 inputs.to(device)
271 outputs = model(**inputs)
272
AttributeError: 'dict' object has no attribute 'to'

Firstly you do not need to replace the CPU with the CUDA everywhere in the code.
You should just add the following to the cell from which you import the libraries
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
By printing the device object, you can see the gpu that google colab assigned to you to use.
Coming to your question, I think instead of giving the dictionary itself, you just need to give values corresponding to the expected keys.

Related

IFC to Cypher via python and IfcOpenShell

I want to convert an IFC file to a graph database to extract adjacency and accessibility of the spaces in the IFC model.
I wanted to use Neo4j, and as a part of this job, I need to extract a Cypher code from the IFC file.
I found this code but when I run it, I encounter the error below:
AttributeError Traceback (most recent call last)
<ipython-input-1-b13704b3ee10> in <module>
20 typeDict = IfcTypeDict()
21
---> 22 assert typeDict['IfcWall'] == ('GlobalId', 'OwnerHistory', 'Name', 'Description', 'ObjectType', 'ObjectPlacement', 'Representation', 'Tag')
23
24 nodes = []
<ipython-input-1-b13704b3ee10> in __missing__(self, key)
15 class IfcTypeDict(dict):
16 def __missing__(self, key):
---> 17 value = self[key] = ifcopenshell.create_entity(key).wrapped_data.get_attribute_names()
18 return value
19
AttributeError: 'str' object has no attribute 'get_attribute_names'
Can anyone help me with this? or any other idea about how I can perform this task?
any help would be greatly appreciated.
Regards.
It seems this script was created for IfcOpenShell v0.5 compiled for IFC2x3 while you are using IfcOpenShell v0.6, which is unfortunately not backwards-compatible. You could either try to use v0.5 or update the script to the v0.6 API.
If you use v0.5, be aware that this version was compiled for a specific IFC version. I believe the published packages are for IFC2x3, thus it will not work with IFC4 files. You could compile for IFC4 though, but then would loose IFC2x3 support. The assertion wouldn't work anymore, because IFC4 walls have one more attribute PredefinedType:
assert typeDict["IfcWall"] == ('GlobalId', 'OwnerHistory', 'Name', 'Description', 'ObjectType', 'ObjectPlacement', 'Representation', 'Tag', 'PredefinedType')
Alternatively if using v0.6 you will have to change more in the script. Maybe like in this updated Gist. There was another issue further down and you might encounter more. If in doubt, try to contact the original author or use the script as an inspiration to write your own conversion.

how to increase buffer size in scilab

I'm using a variable that is using too large symbol/string in Scilab, which is giving following error:
Too large string. at line 44 of exec file called by :
exec('/proj/shubhamj/shubhamj/scilab/final_add_from_script.sce', -1)
I've already used stacksize('max').
According to this thread on the mailing list for Scilab the error comes from the length of the command. You can get the same error without the exec() if you call a command that is too long even in your current script (where the exec() call currently is).
If we look at the documentation the default stacksize is approx. 76MB (megabytes) and that is a lot of characters which makes this issue 99.9% not related to the size of the stack.

Weird AttributeError: OpenMDAO says param has not been initialized when I run my simulation under mpirun

I am running developmental scientific code. I am stuck on a cryptic error message, and am curious what the OpenMDAO team thinks. When I run the code in serial, it works with no issues. When I run it under mpirun, OpenMDAO throws a cryptic error message:
Traceback (most recent call last):
File "test/exampleOptimizationAEP.py", line 129, in <module>
prob['ratedPower'] = ratedPower
.....
File "/scratch/jquick/test/lib/python2.7/site-packages/openmdao-1.7.3-py2.7.egg/openmdao/core/vec_wrapper.py", line 1316, in __setitem__
(self.name, name))
AttributeError: 'params' has not been initialized, setup() must be called before 'ratedPower' can be accessed
I am not sure how to approach this. There is nothing obviously different about the ratedPower variable in the code. What information does this error give me about what is going wrong?
This is a bug in OpenMDAO <= v1.7.2. Look at the output of check_setup and see the list of parameters without associated unknowns. You will find that variable in there. When running in parallel (because of the bug), you can not set any hanging params (ones without associated unknowns) in your setup script.
The way to fix it is to add an IndepVarComp to any variable you need to initialize the value of.

Bokeh: Models must be owned by only a single document

I'm working with Bokeh 0.12.2 in a Jupyter notebook and it frequently throws exceptions about "Models must be owned by only a single document":
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
<ipython-input-23-f50ac7abda5e> in <module>()
2 ea.legend.label_text_font_size = '10pt'
3
----> 4 show(column([co2, co, nox, o3]))
C:\Users\pokeeffe\AppData\Local\Continuum\Anaconda3\lib\site-packages\bokeh\io.py in show(obj, browser, new, notebook_handle)
308 '''
309 if obj not in _state.document.roots:
--> 310 _state.document.add_root(obj)
311 return _show_with_state(obj, _state, browser, new, notebook_handle=notebook_handle)
312
C:\Users\pokeeffe\AppData\Local\Continuum\Anaconda3\lib\site-packages\bokeh\document.py in add_root(self, model)
443 self._roots.append(model)
444 finally:
--> 445 self._pop_all_models_freeze()
446 self._trigger_on_change(RootAddedEvent(self, model))
447
C:\Users\pokeeffe\AppData\Local\Continuum\Anaconda3\lib\site-packages\bokeh\document.py in _pop_all_models_freeze(self)
343 self._all_models_freeze_count -= 1
344 if self._all_models_freeze_count == 0:
--> 345 self._recompute_all_models()
346
347 def _invalidate_all_models(self):
C:\Users\pokeeffe\AppData\Local\Continuum\Anaconda3\lib\site-packages\bokeh\document.py in _recompute_all_models(self)
367 d._detach_document()
368 for a in to_attach:
--> 369 a._attach_document(self)
370 self._all_models = recomputed
371 self._all_models_by_name = recomputed_by_name
C:\Users\pokeeffe\AppData\Local\Continuum\Anaconda3\lib\site-packages\bokeh\model.py in _attach_document(self, doc)
89 '''This should only be called by the Document implementation to set the document field'''
90 if self._document is not None and self._document is not doc:
---> 91 raise RuntimeError("Models must be owned by only a single document, %r is already in a doc" % (self))
92 doc.theme.apply_to_model(self)
93 self._document = doc
RuntimeError: Models must be owned by only a single document, <bokeh.models.tickers.DaysTicker object at 0x00000000042540B8> is already in a doc
The trigger is always calling show(...) (although never the first time after kernel start-up, only subsequent calls).
Based on the docs, I thought reset_output() would return my notebook to an operable state but the exception persists. Through trial-and-error, I've determined it's necessary to also re-define everything being passing to show(). That makes interactive work cumbersome and error-prone.
[Ref]:
reset_output(state=None)
  Clear the default state of all output modes.
  Returns: None
Am I right about reset_output() -- is it supposed to resolve the situation causing this exception?
Else, how do I avoid this kind of exception?
It may be because of conflicting objects that has the same name. you need to create completely new objects every time.
Seems it can by fixed by differentiating the source name
Like this:
source1 = df
p1.circle('A', 'B', source=source1)
source2 = df
p2 = figure()
p2.circle('C', 'D', source=source2)
sourceN = df
p2 = figure()
p2.circle('X', 'Y', source=sourceN)
I've been working in a jupyterlab notebook iterating on visualizations of a large amount of data with bokeh, holoviews, and panel, and have been running into this issue periodically.
Here are a couple of additional things that may help. Note that p is used as the bokeh conventional name for the figure. I am posting on this old thread because it was the top result in my Google search for the error message.
Try clearing the document (found in docs):
from bokeh.io import curdoc
curdoc().clear()
I observed that panel was able to display a bokeh object even when bokeh show would not.
import panel as pn
pn.extension()
pn.pane.Bokeh(p)
Digging into how panel is able to display an object even when bokeh is not, I noticed this function, which fixed the problem for me:
import panel as pn
pn.io.model.remove_root(p)
If you don't have panel installed, here is the source code from above:
from bokeh.models import Model
for model in p.select({'type': Model}):
prev_doc = model.document
model._document = None
if prev_doc:
prev_doc.remove_root(model)
Hopefully this helps someone, or future me.
I ran into this error message when using file_html from from bokeh.embed, after i upgraded to bokeh version 1.01. Downgrading again to bokeh version 0.12.16 solved it. (pip install bokeh==0.12.16)
Note sure why.
This solution works without upgrading or downgrading packages.
try:
reset_output()
output_notebook()
show(p)
except:
output_notebook()
show(p)
Solution provided here :
https://github.com/bokeh/bokeh/issues/8579
Try using after creating each plot. add_root will add that model as a root of the current Document, making sure that each Model is added to a single Document:
curdoc().add_root(column([plot]))
curdoc().title = doc_title //Add a title to the doc
show(figure)
Note: column(the list of plots) can be replaced with any object which inherits the Model class.
Refer to the link for more details on add_root and bokeh Documents: https://docs.bokeh.org/en/latest/docs/reference/document.html?highlight=add_root#bokeh.document.document.Document.add_root
column_data_source = ColumnDataSource(dataframe)
After each row in the jupyter notebook that used the column data source we have to make it again simply. The column data source seems like we cant use it many times in the same code.
This seems a little hack but it worked for me when i faced the same error.

abap runtime error program line too long

Good day. The programs function is to take an equipment number (or none), display that number with a description (or all) in alv, and then run IE03 should the user double click on
Program worked fine in client 110, but in 150 a runtime error happens. This morning I tried to make a new program with a shorter name (only lead I had), activated it (window popped up asking me to activate the previous version as well). That didn't work and now the original doesn't work in either.
The program "SAPLSKBH" is terminating because program line is too long, being 78 chars wide which is too much for the internal table "\FUNCTION=K_KKB_FIELDCAT_MERGE\DATA=L_ABAP_SOURCE[]"
It sounds like you are using REUSE_ALV_GRID_DISPLAY for output, is that correct?
Check you source code; somewhere you have a line that is more than 78 characters. The function K_KKB_FIELDCAT_MERGE takes the source code of your program to produce a structure that corresponds to the table/structure you give it. (In the old days, there was a limit of 78 characters width for a line of ABAP code, and this is an old function module).
You can alternatively build a field catalog yourself in code, rather than use this function.

Resources