# TR-GPT-CF: A Topic Refinement Method Using GPT and Coherence Filtering
## 2 Materials and Methods
### Misaligned Word Replacement  
This function is designed to improve topic coherence by replacing an identified misaligned word in a topic with a better alternative [38]. It employs a dual approach for generating replacement candidates. First, it uses WordNet to identify synonyms and semantically related words based on the centroid word of the topic. Second, it leverages GPT to generate replacements that are more contextually relevant. These candidates are then combined into a unified set to ensure their uniqueness. The function evaluates each candidate by temporarily replacing the misaligned word in the topic and calculating the resulting topic coherence score. If a candidate produces a higher coherence score than the original topic, it is selected as the best replacement. Additionally, the function prevents redundancy by ensuring that duplicate words are not added to the topic. WordNet is a large lexical database of the English language that organizes words into sets of synonyms called synsets [51; 52]. Each synset contains lemmas that are synonymous or closely related terms. WordNet facilitates the exploration of lexical relationships, providing synonyms, hypernyms, and hyponyms for the centroid word. Hypernyms are more general, while hyponyms are more specific. We utilize it to generate candidates for a given centroid word. It extracts synonyms and lemmas for the centroid word to create a list of potential replacements. By querying WordNet for all synsets associated with the centroid word, we retrieve various semantic contexts for that word. Consider the following workflow as an illustration: the input consists of topic words: ['education', 'learning', 'knowledge', 'teaching'], with 'learning' identified as the centroid word. WordNet's synsets for 'learning' include ['learning.n.01', 'learning.n.02'], and the lemmas derived from these synsets are ['learning', 'acquisition', 'education','study']. Therefore, the output for WordNet candidates is ['learning', 'acquisition', 'education','study']. We extended our search for candidate words by also leveraging GPT-3.5-_turbo-1106_ in addition to using WordNet. We developed a function that can be invoked within the misaligned word replacement function to generate alternative words by constructing a clear and explicit GPT prompt. This prompt instructs GPT to provide alternative words for the centroid word, ensuring that the generated output is structured as a comma-separated list. For testing purposes, we used Google Colab's T4 GPU, which provides free GPU acceleration, making it a convenient and cost-effective environment for running computationally intensive models. However, the framework is not limited to this environment and can run on any computational platform with sufficient resources. We leveraged OpenAI's API version 1.55.3 [64], setting the temperature parameter to 0 for deterministic responses, to ensure minimal randomness and consistent results, and max_tokens to 100, to prevent overly long responses. This version was chosen because of its improved compatibility and stability, addressing previous integration concerns and ensuring reliable performance for our framework. We used the following prompt to query GPT-3.5 for alternative words:  
\"Provide alternative words for '(_centroid_word_)' in the context of the topic: _[topic_word_]_. Please separate words with commas\". The function sends the prompt to GPT via the OpenAI's API using the client.chat.completions.create method. As previously discussed in this section, we will select the candidate with the highest coherence score to replace the misaligned word, using the topic coherence metric _C_v_. We utilized Gensim's CoherenceModel to assess this coherence score of the topics, as it has been widely used in recent studies, including [65], for evaluating topic modeling performance. In this work, we focus solely on topic coherence metric _C_v_[66], which encompasses a set of measures that describe the quality and interpretability of topics from a humanperspective [27; 67].