I came across the FastText class while reading an article that I found here...
https://stackabuse.com/python-for-nlp-working-with-facebook-fasttext-library/#disqus_thread
The author has used an undefined object "word_tokenized_corpus".
ft_model = FastText(word_tokenized_corpus,
size=embedding_size,
window=window_size,
min_count=min_word,
sample=down_sampling,
sg=1,
iter=100)
I am getting an error for obvious reason. How do I correctly initiate the class?
The article has been updated by the author and the following code was added:
final_corpus = [
preprocess_text(sentence)
for sentence in artificial_intelligence
if sentence.strip() != ""
]
word_punctuation_tokenizer = nltk.WordPunctTokenizer()
word_tokenized_corpus = [
word_punctuation_tokenizer.tokenize(sent) for sent in final_corpus
]
Related
I want to create a learner in mlr3, using the distRforest package.
my code:
library(mlr3extralearners)
create_learner( pkg = "." ,
classname = 'distRforest',
algorithm = 'regression tree',
type = 'regr',
key = 'distRforest',
package = 'distRforest',
caller = 'rpart',
feature_types = c("logical", "integer", "numeric","factor", "ordered"),
predict_types = c('response'),
properties = c("importance", "missings", "multiclass",
"selected_features", "twoclass", "weights"),
references = FALSE,
gh_name = 'CL'
)
gives the following error : Error in sprintf(msg, ...) : too few arguments
in fact, replicating the code in the tutorial https://mlr3book.mlr-org.com/extending-learners.html throws the same error.
Any ideas? Thanks a lot - c
thanks for your interest in extending the mlr3 universe!
Couple of things, firstly the example in the book works fine for me, and secondly your example cannot work because you are including classif properties for a regr learner. As I am unable to reproduce your error it's hard for me to debug what's going wrong, it would be helpful if you could run the following:
reprex::reprex({
create_learner(
pkg = ".",
classname = "Rpart",
algorithm = "decision tree",
type = "classif",
key = "rpartddf",
package = "rpart",
caller = "rpart",
feature_types = c("logical", "integer", "numeric", "factor", "ordered"),
predict_types = c("response", "prob"),
properties = c("importance", "missings", "multiclass", "selected_features", "twoclass", "weights"),
references = TRUE,
gh_name = "CL"
)
}, si = TRUE)
If you're still getting an error and the output is too long to print here then head over to the GitHub and open an issue there.
I'm getting same error as this question, but with XQuery:
SaxonApiException: The context item for axis step ./CLIENT is absent
When running from the command line, all is good. So I don't think there is a syntax problem with the XQuery itself. I won't post the input file unless needed.
The XQuery is displayed with a Console.WriteLine before the error appears:
----- Start: XQUERY:
(: FLWOR = For Let Where Order-by Return :)
<MyFlightLegs>
{
for $flightLeg in //FlightLeg
where $flightLeg/DepartureAirport = 'OKC' or $flightLeg/ArrivalAirport = 'OKC'
order by $flightLeg/ArrivalDate[1] descending
return $flightLeg
}
</MyFlightLegs>
----- End : XQUERY:
Error evaluating (<MyFlightLegs {for $flightLeg in root/descendant::FlightLeg[DepartureAirport = "OKC" or ArrivalAirport = "OKC"] ... return $flightLeg}/>) on line 4 column 20
XPDY0002: The context item for axis step root/descendant::FlightLeg is absent
I think that like the other question, maybe my input XML file is not properly specified.
I took the samples/cs/ExamplesHE.cs run method of the XQuerytoStream class.
Code there for easy reference is:
public class XQueryToStream : Example
{
public override string testName
{
get { return "XQueryToStream"; }
}
public override void run(Uri samplesDir)
{
Processor processor = new Processor();
XQueryCompiler compiler = processor.NewXQueryCompiler();
compiler.BaseUri = samplesDir.ToString();
compiler.DeclareNamespace("saxon", "http://saxon.sf.net/");
XQueryExecutable exp = compiler.Compile("<saxon:example>{static-base-uri()}</saxon:example>");
XQueryEvaluator eval = exp.Load();
Serializer qout = processor.NewSerializer();
qout.SetOutputProperty(Serializer.METHOD, "xml");
qout.SetOutputProperty(Serializer.INDENT, "yes");
qout.SetOutputStream(new FileStream("testoutput.xml", FileMode.Create, FileAccess.Write));
Console.WriteLine("Output written to testoutput.xml");
eval.Run(qout);
}
}
I changed to pass the Xquery file name, the xml file name, and the output file name, and tried to make a static method out of it. (Had success doing the same with the XSLT processor.)
static void DemoXQuery(string xmlInputFilename, string xqueryInputFilename, string outFilename)
{
// Create a Processor instance.
Processor processor = new Processor();
// Load the source document
DocumentBuilder loader = processor.NewDocumentBuilder();
loader.BaseUri = new Uri(xmlInputFilename);
XdmNode indoc = loader.Build(loader.BaseUri);
XQueryCompiler compiler = processor.NewXQueryCompiler();
//BaseUri is inconsistent with Transform= Processor?
//compiler.BaseUri = new Uri(xqueryInputFilename);
//compiler.DeclareNamespace("saxon", "http://saxon.sf.net/");
string xqueryFileContents = File.ReadAllText(xqueryInputFilename);
Console.WriteLine("----- Start: XQUERY:");
Console.WriteLine(xqueryFileContents);
Console.WriteLine("----- End : XQUERY:");
XQueryExecutable exp = compiler.Compile(xqueryFileContents);
XQueryEvaluator eval = exp.Load();
Serializer qout = processor.NewSerializer();
qout.SetOutputProperty(Serializer.METHOD, "xml");
qout.SetOutputProperty(Serializer.INDENT, "yes");
qout.SetOutputStream(new FileStream(outFilename,
FileMode.Create, FileAccess.Write));
eval.Run(qout);
}
Also two questions regarding "BaseURI".
1. Should it be a directory name, or can it be same as the Xquery file name?
2. I get this compile error: "Cannot implicity convert to "System.Uri" to "String".
compiler.BaseUri = new Uri(xqueryInputFilename);
It's exactly the same thing I did for XSLT which worked. But it looks like BaseUri is a string for XQuery, but a real Uri object for XSLT? Any reason for the difference?
You seem to be asking a whole series of separate questions, which are hard to disentangle.
Your C# code appears to be compiling the query
<saxon:example>{static-base-uri()}</saxon:example>
which bears no relationship to the XQuery code you supplied that involves MyFlightLegs.
The MyFlightLegs query uses //FlightLeg and is clearly designed to run against a source document containing a FlightLeg element, but your C# code makes no attempt to supply such a document. You need to add an eval.ContextItem = value statement.
Your second C# fragment creates an input document in the line
XdmNode indoc = loader.Build(loader.BaseUri);
but it doesn't supply it to the query evaluator.
A base URI can be either a directory or a file; resolving relative.xml against file:///my/dir/ gives exactly the same result as resolving it against file:///my/dir/query.xq. By convention, though, the static base URI of the query is the URI of the resource (eg file) containing the source query text.
Yes, there's a lot of inconsistency in the use of strings versus URI objects in the API design. (There's also inconsistency about the spelling of BaseURI versus BaseUri.) Sorry about that; you're just going to have to live with it.
Bottom line solution based on Michael Kay's response; I added this line of code after doing the exp.Load():
eval.ContextItem = indoc;
The indoc object created earlier is what relates to the XML input file to be processed by the XQuery.
I have a mongodb collection with the following document:
{
"_id" : ObjectId("5c879a2f277d8132d6707792"),
"a" : "133",
"b" : "daisy",
"c" : "abc"
}
When I run the following mongocxx code:
auto r = client["DB"]["Collection"].find_one({}).value().view();
isREmpty = r.empty();
rLength = r.length();
isOneInR = r.begin() == r.end();
for (bsoncxx::document::element ele : r) {
std::cout << "Got key" << std::endl;
}
I get isREmpty = false, rLength = 99, isOneInR = true and no output saying Got key.
I was expecting the print of "Got key" because one document returned from find_one.
Why isn't it showing?
You are viewing freed memory. The call to .value() creates a temporary bsoncxx::value object. You then get a view into that temporary object with .view() and attempt to examine the data, but it is too late.
What you want to do instead is capture the cursor returned by find_one:
auto cursor = client["DB"]["Collection"].find_one({});
Please see the examples for more details, but here is a quick example: https://github.com/mongodb/mongo-cxx-driver/blob/master/examples/mongocxx/query.cpp#L43
Lifetime management in the C++ driver requires attention. Please read the doc comments for the methods you use, as they will almost always describe the rules you must follow.
I am using Eureka Forms to build a survey form and have not been able to design my swift properly to overcome the error with duplicate tags.
Many of the questions need only a "Yes/No" type answer and I decided to use the ImageCheckRow selectableValue as found in the Example Project. However I can't figure out how to have two or more List Sections in the same form that re-use the "YES/NO" answer as the code below throws a
Thread 1: Assertion failed: Duplicate tag userAnswer
My code so far
form +++
let userAnswer = ["Yes", "No"]
SelectableSection<ImageCheckRow<String>>("question_one", selectionType: .singleSelection(enableDeselection: true))
form.last!.header = HeaderFooterView(title: "Are you a registered member?")
form.last!.tag = "question_one"
for option in userAnswer {
form.last! <<< ImageCheckRow<String>(option){ lrow in
lrow.title = option
lrow.selectableValue = option
lrow.value = nil
lrow.tag = "question_one"
}
}
SelectableSection<ImageCheckRow<String>>("question_two", selectionType: .singleSelection(enableDeselection: true))
form.last!.header = HeaderFooterView(title: "Have you managed to do ...")
form.last!.tag = "question_two"
for option in userAnswer {
form.last! <<< ImageCheckRow<String>(option){ lrow in
lrow.title = option
lrow.selectableValue = option
lrow.value = nil
lrow.tag = "question_two"
}
}
I tried adding the low.tag based on the answer in this question Upload Eureka form data to firebase
but the problem remains.
it looks to me you are adding 2 options with the same tag...
shouldn't you use:
lrow.tag = "question_one_" + option
I get the following error in caret trainControl() using the custom methods syntax documented in the package vignette (pdf) on page 46. Does anyone know if this document out of date or incorrect? It seems at odds with the caret documentation page where the "custom" parameter is not used.
> fitControl <- trainControl(custom=list(parameters=lpgrnn$grid, model=lpgrnn$fit,
prediction=lpgrnn$predict, probability=NULL,
sort=lpgrnn$sort, method="cv"),
number=10)
Error in trainControl(custom = list(parameters = lpgrnn$grid, model = lpgrnn$fit, :
unused argument (custom = list(parameters = lpgrnn$grid, model = lpgrnn$fit,
prediction = lpgrnn$predict, probability = NULL, sort = lpgrnn$sort, method = "cv",
number = 10))
The cited pdf is out of date. The caret website is the canonical source of documentation.