text:
SpaCy v3: Error when training non-blank NLP model
Apologies for reposting this question from Stack Overflow, but I think this Stack Exchange would be more suited.
I've found this nice example of sentiment analysis implementation, however it does not really work with spacy V3. I managed to get it working with spaCy's later versions like this (feel free to use it!):
import spacy
import os
import random
from spacy.util import minibatch, compounding
import  pandas as pd
from spacy.training.example import Example

def load_training_data(
    data_directory: str = "../trainPath", split: float = 0.8, limit: int = 0
) -> tuple:
    # Load from files
    reviews = []
    for label in ["pos", "neg"]:
        labeled_directory = f"{data_directory}/{label}"
        for review in os.listdir(labeled_directory):
            if review.endswith(".txt"):
                with open(f"{labeled_directory}/{review}", encoding="utf-8") as f:
                    text = f.read()
                    text = text.replace("<br />", "\n\n")
                    if text.strip():
                        spacy_label = {
                            "cats": {
                                "pos": "pos" == label,
                                "neg": "neg" == label,
                            }
                        }
                        reviews.append((text, spacy_label))
    random.shuffle(reviews)

    if limit:
        reviews = reviews[:limit]
    split = int(len(reviews) * split)
    return reviews[:split], reviews[split:]

def train_model(training_data: list, test_data: list, iterations: int = 20):
    print(f"Loading the nlp model")
    # nlp = spacy.load("en_core_web_sm")
    # nlp = spacy.load("en_core_web_lg")
    nlp = spacy.blank("en")

    print(f"Adding textcat pipe")
    if "textcat" not in nlp.pipe_names:
        # textcat = nlp.add_pipe("textcat",config=single_label_cnn_config, last=True)
        textcat = nlp.add_pipe("textcat",  last=True)
    else:
        print("Textcat pipe already present.")
        textcat = nlp.get_pipe("texcat")

    textcat.add_label("pos")
    textcat.add_label("neg")

    print()
    # optimizer = nlp.create_optimizer()
    optimizer = nlp.begin_training()
    print("Beginning training")
    print("Loss\tPrecision\tRecall\tF-score")
    batch_sizes = compounding(
    4.0, 32.0, 1.001
    )
    print("Shuffling the data:")
    random.shuffle(training_data)
    # for datum in training_data:
    #     print(datum)
    for i in range(iterations):
        print(f"Training iteration {i}")
        loss = {}
        random.shuffle(training_data)
        batches = minibatch(training_data, size=batch_sizes)
        for batch in batches:
            examples = []
            for text, labels in batch:
                examples.append(Example.from_dict(nlp(text), labels))
            nlp.update(examples, drop=0.2, sgd=optimizer, losses=loss)

        evaluation_results = evaluate_model(tokenizer=nlp.tokenizer, textcat=textcat, test_data=test_data)
        print(
            f"{loss['textcat']}\t{evaluation_results['precision']}"
            f"\t{evaluation_results['recall']}"
            f"\t{evaluation_results['f-score']}"
        )
    # print(f"Value of optimizer averages: {optimizer.averages}")
        # with textcat.model.use_params(optimizer.averages):
        #     print("test")
    # Save model
    with nlp.use_params(optimizer.averages):
        nlp.to_disk("model_artifacts")

def evaluate_model(
    tokenizer, textcat, test_data: list
) -> dict:
    reviews, labels = zip(*test_data)
    reviews = (tokenizer(review) for review in reviews)
    true_positives = 0
    false_positives = 1e-8  # Can't be 0 because of presence in denominator
    true_negatives = 0
    false_negatives = 1e-8
    for i, review in enumerate(textcat.pipe(reviews)):
        true_label = labels[i]
        pos_label = true_label["cats"].get("pos", False)

        # Get the predicted label with the highest score
        predicted_label, score = max(review.cats.items(), key=lambda x: x[1])

        if predicted_label == "neg":
            continue
        if score >= 0.5 and pos_label:
            true_positives += 1
        elif score >= 0.5 and not pos_label:
            false_positives += 1
        elif score < 0.5 and not pos_label:
            true_negatives += 1
        elif score < 0.5 and pos_label:
            false_negatives += 1

    precision = true_positives / (true_positives + false_positives)
    recall = true_positives / (true_positives + false_negatives)

    if precision + recall == 0:
        f_score = 0
    else:
        f_score = 2 * (precision * recall) / (precision + recall)
    return {"precision": precision, "recall": recall, "f-score": f_score}

def test_model(input_data):
    #  Load saved trained model
    loaded_model = spacy.load("model_artifacts")
    # Generate prediction
    parsed_text = loaded_model(input_data)
    # Determine prediction to return
    if parsed_text.cats["pos"] > parsed_text.cats["neg"]:
        prediction = "Positive"
        score = parsed_text.cats["pos"]
    else:
        prediction = "Negative"
        score = parsed_text.cats["neg"]
    print(
        f"Review text: {input_data}\nPredicted sentiment: {prediction}"
        f"\tScore: {score}"
    )

The only issue is that it works only with blank nlp models. If I try to load a model with more than the textcat component, this line:
                nlp.update(examples, drop=0.2, sgd=optimizer, losses=loss)

Raises the following error:
"ValueError: Cannot get dimension 'nO' for model 'sparse_linear': value unset"
I would like to add an entity-ruler component to the pipeline, therefore I was wondering if anyone has any idea how to modify this so that it works for pre-trained models.
I tried to use
        optimizer = nlp.create_optimizer()

And
        optimizer = nlp.resume_training()

Instead of begin_training() coupled with a non-blank models, as well as using nlp.make_doc(text) instead of nlp(text) to obtain the doc object with the tokens only, but the error persists. Any suggestions?

Hi, please change the title of your questioj to be specific to your problem

Hi! I reformulated the title, however I am not sure how more specific should I get, nor if it was too unclear before.


text:
What effect is expected if LoRA is applied after Fine-tuning?
I am currently learning several things about the ASR Transformer model.
Recently, I learned LoRA and Adapter.
It certainly seems to have an advantage over fine-tuning in general.
But here I came up with an interesting idea.
For example, if fine-tune an ASR model with specific speech data, and apply LoRA again to the generated model, what effect can you expect?
For instance, after fine-tuning an ASR with voices of the elderly only, what effects can we expect if we then apply LoRA using voices of the elderly with laryngeal disorders only?
Thank you for reading.

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/

sort: votes


text:
WSL2 With Tensorflow 2.16 dosent detect my gpu in PyCharm but does in console
WSL2 With Tensorflow 2.16 dosent detect my gpu in PyCharm but does in console.. essentially what the title said.
Console output

While when I try to use the same env in pycharm I get:

I am stuck and don't know where to go from here..

Was unable to resolve it... rewrote my models to pytorch works fine..

Things you try checking:

check if you are using the same environment in both cases.
Try reinstalling tensorflow using pip install "tensorflow[+cuda]" as mentioned here

To get better help, try posting more details like Versions instead of screenshots.Other may downvote the post because of the low details of the post. Please check at stackoverflow, similar posts are already mentioned over there

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/


text:
Art intuitive-random pattern recognition -from art to LLM
I have a big data set of intuitive paintings with lots of random shape recognition that I have done by myself. How can LLM use it to explore it further for more pattern recognitions?

Welcome to AI Stack Exchange. It's not clear what you are trying to do. Could you give some more details and maybe an example of what "good" output might look like? Use [edit] to add details to the original question

I'm trying to test and see whether LLMs can benefit from intuitive pattern recognition learning. It's just another potential way of visualising images (intuitive predictions/visualisations)- for estimated/predicitve work. LLM would "search" existing patterns to extract the meaning, with "ready-filled stencils." Use may be in eg. medicine-to see changes/protein folding etc before these actually fully take place. Sorry for the limited space-I may have another go to try to be clearer. I think it's worth a try.ps. Teaching LLM intuitive pattern recogn. for many reasons-hence art very suitable..


text:
ChatGPT Plus seemingly gives access to more sophisticated models than I can access via the API? /confused
I've spent the past day researching different AI models and have come to the conclusion that I am overpaying at $20 per month for a ChatGPT Plus subscription, since the consensus seems to be that I can get the same service just using their API via a front end UI (I have set up LibreChat for this purpose and fed it my API keys). I was under the impression this would give me the access to the same latest ChatGPT model as I converse with in a ChatGPT Plus window? At the time of writing, this is apparently gpt-4-0125-preview.
However, when I interrogated the AI about its training data (via the API / LibreChat) as a test, (ostensibly gpt-4-0125-preview), it tells me its training data is only made up until September 2021? (Figure 1)
Asking the same question in the ChatGPT Plus window, the AI tells me it's 2023, as I would expect, according to the official OpenAI docs. (Figures 2 & 3)
Please see the attached screenshots, and tell me what I'm missing here?
Also, if someone could answer this explicitly: does a ChatGPT Plus subscription give me something that the API doesn't? What is the difference? I'm confused... and really, I've wasted enough time with this now. I've spent most of my Saturday setting up LibreChat to run on my server at a custom domain, only to find the whole thing apparently provides a significantly lesser service that ChatGPT Plus does after-all. I guess at least I didn't cancel my subscription just yet...

This stackexchange is for the discussion of AI, not pre-trained models or their use.  The genai stackexchange is probably better suited for this question.

please do not put question marks on end of statements ... that is not how questions are formed


text:
Intuition and technical explanation behind "3D-aware Feature Attention" in Sync Dreamer? (Multiview Generating Diffusion Model)
I am looking to understand the whole block on how the Sync Dreamer paper has constructed the "3D aware feature attention" which is outlined on page 5.

To
enforce consistency among multiple generated views, it is
desirable for the network to perceive the corresponding features
in 3D space when generating the current image. To
achieve this, we first construct a 3D volume with V 3 vertices
and then project the vertices onto all the target views
to obtain the features. The features from each target view
are concatenated to form a spatial feature volume. Next,
a 3D CNN is applied to the feature volume to capture and
process spatial relationships. In order to denoise n-th target
view, we construct a view frustum that is pixel-wise aligned
with this view, whose features are obtained by interpolating
the features from the spatial volume. Finally, on every intermediate
feature map of the current view in the UNet, we
apply a new depth-wise attention layer to extract features
from the pixel-wise aligned view-frustum feature volume
along the depth dimension.

I don't really understand much that's going on here and have many doubts:

What does it mean to project 3D vertices onto a set of target views? Can you get the 2D plane for a target view purely based on the azimuth angle and elevation? How do you restrict this 2D plane in size during projection?

What does it mean to have a view-frustum "aligned pixel-wise with the target view"?

What exactly is this depth-wise attention layer? I need some visualization intuition.


text:
Is SVM (support vector machine) iterative?
a - First I want to understand in a simple (1D or 2d case without any kernel tricks) whether the process of fitting the best-separating line is iterative just like in Neural Networks with some loss function while the separating line's parameters are adjusted till we get the best fitting results.
Or maybe it is more like in the linear regression case, where of course I can iterate to find the best-fitted line, but there is no need to since in the case of linear regression there is a straightforward equation that returns me the slope, and the intercept of the best-fitted line while in the input are the coordinates of all observation points.
Another part of the question is regarding the famous Kernel trick (guess and maybe the answer relates to the first part of the question asked above):
b -  Is the process of curving the space with observations iterative or not? After all, there is an infinite number of variations one can curve the plane with observations.
Thank you very much

How can you curve a XOR function within a 2-d plane to become linearly separable?

If you have initially your data in 2d the kernel trick puts the data on a curved 2d plane in 3d space and cuts this  curved 2d plane with noncurved - linear 2d plane in 3d space
I have asked why this is better (or not?) then leaving the data in 2d space and curve the cutting plane to be curved 2d surface in 3d space that cuts the data remainig on a flat 3d plane in 3d space

Please, split this post into multiple ones, one for each question.


text:
How to start creating a ChatGPT conversation system like for any specific domain data (Judicial)?
I have a sufficient amount of relevant data about my domain. It includes data in Oracle DB as of now. Could someone guide me in the right direction as a novice how do I choose the right tools and frameworks to deploy and with which model I need to integrate etc stuff to start developing a simple tool?


text:
Lost when trying to get good time series prediction results (regression problem) even after trying many things
I'm not able to get good results after a long time testing when using TensorFlow to predict time series data (regression problem). I don't know if the problem is with the data (little quantity and/or low quality) or with the model (or if there is a problem with both) (although I have tried several and tested various combinations of hyperparameters). I'm really tired and I don't know what else to do. What would you do if you were in my place? Thanks in advance for any help you can give me.


text:
is it possible to use crop classification, health assessment of crops and crop yielding prediction in the same model
I was wondering if it is possible to create a model in which the crop data is used for classification of crops and thenthe outputs is subsequently used for health assessment of that particular crop and after the health assessment to predict the yield . and i yes which appproach should i use?

Can you provide more details about what you mean by "crop data" provide some actual examples with real images that we can see? What are some possible labels in your case? This post is not very clear (at least to me).


text:
Where do I found multiple choice questions dataset?
I'm trying to train a GPT model to generate multiple choice questions about programming language, but I couldn't find any suitable dataset that contains mcq with answer about any programming language like c++, java, etc.., I searched in all the dataset websites but found nothing, how to I found one?


text:
Kmeans centroids not in center of cluster
i've been trying to implement Kmeans algorithm from scratch and the problem with my centroids is they don't seem to be going towards the center of clusters.

here is the code i wrote:
import pandas as pd
from sklearn.preprocessing import StandardScaler
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.decomposition import PCA
from sklearn.preprocessing import StandardScaler
class KMeans:
    def __init__(self, k=3, max_iter=50):
        self.k = k
        self.max_iter = max_iter
        self.centroids = None
        self.data=None
    def preprocess(self):
        self.data = self.data.dropna()

    def load_data(self, data):
        cols = ["overall", "age", "potential", "wage_eur", "value_eur"]
        data = data[cols]
        data = data[:2500]
        scaler = StandardScaler().set_output(transform="pandas")
        data = scaler.fit_transform(data)
        self.data = data
        print(self.data.describe())
        self.centroids = self.data.sample(n=self.k)
        self.centroids.index = [i for i in range(self.k)]
    def __calculate_distance(self, distance):
        for i in self.data.index:
                for j in range(self.k):
                    distance.loc[i, j] = np.sqrt(np.sum(((self.data.loc[i, :] - self.centroids.loc[j, :])**2)))
        return distance
    def __plot(self, data, labels, centroids):
        pca = PCA(n_components=2)
        data_2d = pca.fit_transform(data)
        centroids_2d = pca.fit_transform(centroids)
        sns.scatterplot(x=data_2d[:, 0], y=data_2d[:, 1], hue=labels, palette=sns.color_palette("bright")[:self.k])
        sns.scatterplot(x=centroids_2d[:, 0], y=centroids_2d[:, 1], color="black")
        plt.draw()
        plt.pause(0.1)
        plt.clf()
    def fit(self):
        distance = pd.DataFrame(columns=[i for i in range(self.k)], index = [i for i in self.data.index])
        for _ in range(self.max_iter):
            self.__calculate_distance(distance)
            labels = distance.idxmin(axis=1)
            self.__plot(self.data, labels, self.centroids)
            self.centroids = self.data.groupby(labels).mean()
            print(self.centroids)
        plt.show()

model = KMeans()
data = pd.read_csv("Kmeans\data\players_22.csv")
model.load_data(data)
model.preprocess()
model.fit()


text:
deep learning for stock prediction
I am learning deep learning . Right now I am using MNIST data set, which contains tens of thousands of scanned images of handwritten digits, together with their correct classifications.
My question how to use time series data like stock market data (how to incorporate stock data with neural networks )
My second question how to know which neural networks is suitable for predicting ?

I think you are looking for a tutorial that explains using stock market data with machine learning. At AI Stack Exchange, the volunteers don't write full tutorials for you on demand, it takes too much effort. I suggest you search for a tutorial and start it. Then, if you hit a problem with understanding any detail, that is where AI Stack Exchange can help you.

@NeilSlater I am just asking the logic/principle  behind using time series data instead of images/audio in first layer of neural network .   I know the hands-on procedure

Have you tried searching for "neural networks for time series"? It's not clear how/why you are stuck.

Or, I threw the exact title of this post into google and the first result was a tutorial on the subject.

Everything can be fed into a neural network as long as you can encode the input and output into tensors.
There are only two model bases in deep learning for every machine learning problem: the regressor model and the classifier model.
For the input tensor, you should encode the time series into a vector. Perhaps you must specify the window size of the input tensor.
Particularly about the output tensor, it's not clear whether your problem is about classification or regression. If its output is the future price in continuous value, then it's a regression, and the output tensor will likely be a future vector relative to the past vector.
If its output is only about whether the price will increase or decrease, then it's a classification problem with two classes (binary classification). Then the vector is likely encoded as 1 (increase) or 0 (decrease) relative to the past vector input.

give me examples say i have csv data of stocks like open close high low


text:
how to represent a piece-wise linear function using linear combination of max function
If given a piece-wise linear function and its turning points, how to represent the function using linear combination of max function?

What have you tried? You should put some effort in your questions.

Does this answer your question: https://math.stackexchange.com/questions/962277/first-degree-spline-interpolation-problem/1018069#1018069


text:
Error in finetune paddleOCR
Anyone help me this error in finetuning paddleOCR. Here the link to Notebook  https://www.kaggle.com/code/ryanlliu/finetune-paddleocr?scriptVersionId=169451466
and dataset https://www.kaggle.com/datasets/ryanlliu/vietnamese-id-card-fields/data


text:
How to changs voice? (Speech to speech)
How to change soms person voice to another person voice (speech to speech) in this way:

First we record our voice.
Then, record second person voice.
Change first voice to second voice. (I mean the output should have first voice sentences but with second person voice.

What are your findings so far?

Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.